Type constructors can take one or more type parameters:
data Foo a b = Bar a b | Biz a b
Type parameters in Haskell must begin with a lowercase letter. Our custom data type is not a real type yet. In order to create values of our type, we must substitute all type parameters with actual types. Because a
and b
can be of any type, our value constructors are polymorphic functions.
let x = Bar "Hello" 10 -- x :: Foo [Char] Integer
let y = Biz "Goodbye" 6.0 -- y :: Fractional b => Foo [Char] b
let z = Biz True False -- z :: Foo Bool Bool