title |
---|
Pattern Synonym on multiple constructors |
ViewPatterns
can be used to define a pattern synonym matching on more than one constructor. An example:
pattern Foo s <-
((\case { SomeConstr1 _ s -> Just s; SomeConstr2 s -> Just s; _ -> Nothing }
) -> Just s
)
lexi.lambda writes:
The
Maybe
wrapping is there to communicate that the pattern-matcher should backtrack on anything other thanSomeConstr1
andSomeConstr2