Data constructors in Haskell provide a means of creating values that inhabit a given type. Data constructors in Haskell have a type and can either be constant values (nullary) or take one or more arguments, like functions. In the following example, Cat is a nullary data constructor for Pet, and Dog is a data constructor
that takes an argument:
-- Why name a cat?
-- They don't answer anyway.
type Name = String
data Pet = Cat | Dog Name
The data constructors have the following types:
Prelude> :t Cat
Cat :: Pet
Prelude> :t Dog
Dog :: Name -> Pet
Data constructors in Haskell provide a means of creating values that inhabit a given type. Data constructors in Haskell have a type and can either be constant values (nullary) or take one or more arguments, like functions. In the following example, Cat is a nullary data constructor for Pet, and Dog is a data constructor that takes an argument:
The data constructors have the following types: