The embedded match is a bit verbose, and there's a minor maintenance hassle in keeping the number of underscores in sync with the definition of A.
You can save a few keystrokes using function
keyword. You can also use _
as a pattern of ignoring everything (it doesn't mean you have to bind to a single value).
myList
|> List.filter (function A _ -> true | _ -> false)
In general, if you repeatedly write functions as above, you should define a few active patterns, one for each case:
let (|ACase|_|) = function
| A _ as x -> Some x
| _ -> None
myList |> List.choose (|ACase|_|)
Is there a way to define this 'constructedFrom' function?
There's no idiomatic way to do so. I think active patterns can remedy the problem most of time.