I’m trying to use an OR pattern, as described here:
let foo = function
| Some (0, x) when x > 0 | None -> "bar"
| _ -> "baz"
However, this gives a compiler error:
error FS0010: Unexpected symbol ‘|’ in pattern matching. Expected ‘->’
or other token.
What am I doing wrong? Does it have to do with the when guard?
A
whenguard refers to a single case, regardless of how many patterns are combined. The cases need to be separated:For that reason, it may be better to factor out the return value, so a possibly complex expression isn’t repeated:
Using an active pattern is another way to avoid such repetition: