[Haskell-cafe] Pattern matching: multi constructors to same branch

Thiago Negri evohunz at gmail.com
Tue Sep 11 18:43:41 CEST 2012

Is it possible to capture more than one constructor in a single
pattern matching?
I mean, is it possible to generalize the following pattern matching of
A and B to a single branch?

g f C = [f C]
g f v@(A _ n) = f v : g n
g f v@(B _ n) = f v : g n

For example:

g f C = [f C]
g f v@(A|B _ n) = f v : g n


g f v =
    case v of
        C -> [f C]
        A|B -> f v : g (n v)


More information about the Haskell-Cafe mailing list