Given the following active pattern:
let (| HasMatch |) (x:string) =
if x.Contains("0") then Some()
else None;;
And the following pattern matching func:
let testFn x = function
| HasMatch i -> printfn "%A" i
| _ -> printf "nope";;
The last line's wildcard pattern says warning FS0026: This rule will never be matched
All of the examples i see seem to infer that partial active patterns must return Some('a)
to match, and that ones that return None
get captured by the wildcard. The error seems to say differently.
What am i missing?
I think you should add the
None
case to the active pattern declaration as follows:In your orignal example, the compiler infers that you actually want to return the
Option
type. When you run theprintf
in your example, you would see it printSome Null
when there is a match.Also, it is bad to return
Some()
, you should return saySome(x)
or similar