F# Partial Active Pattern Matching "Rule Will Never Be Matched" -


given following active pattern:

let (| hasmatch |) (x:string) =    if x.contains("0") some()   else none;; 

and following pattern matching func:

let testfn x = function   | hasmatch -> printfn "%a"   | _ -> printf "nope";; 

the last line's wildcard pattern says warning fs0026: rule never matched

all of examples see seem infer partial active patterns must return some('a) match, , ones return none captured wildcard. error seems differently.

what missing?

i think should add none case active pattern declaration follows:

let (| hasmatch | _ |) (x:string) =    if x.contains("0") some()   else none;; 

in orignal example, compiler infers want return option type. when run printf in example, see print some null when there match.

also, bad return some(), should return some(x) or similar


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -