Can I match a data constructor wildcard in Haskell?

Nope. But you can write this:

data Foo
    = X { name :: String, age :: Int } 
    | A { name :: String }
    | B { name :: String }
    | C { name :: String }
    | D { name :: String }

and then have name :: Foo -> String. You could also consider this:

data Tag = A | B | C | D | X Int
data Foo = Tagged Tag String

f (Tagged _ s) = s

Leave a Comment