Is there any way to use a discriminated union of the following form with active pattern matching? I haven't been able to find any examples.
This is what I'm trying to do:
type c = a | b
type foo =
| bar1
| bar2 of c
//allowed
let (|MatchFoo1|_|) aString =
match aString with
| "abcd" -> Some bar1
| _ -> None
//not allowed
let (|MatchFoo2|_|) aString =
match aString with
| "abcd" -> Some (bar2 of a)
| _ -> None
Why can "Some" not be used in the second way? Is there another way to achieve the same thing?
You only need to use
of
when declaring the type, so you can just construct values with thebar2
constructor like:Your second function should work if you change it to: