In type theory and Haskell, an entity that specifies a type in terms of parameters; equivalently, a paramaterized data type
In type theory and in the haskell programming language, a type constructor is an entity that specifies a new data-type, given one or more parameters. For example, in Haskell, the 2-tuple type constructor (,)
can be applied to the types Int
and String
to create the type of (Int, String)
tuples.
In Haskell, where basic types like Int
have kind *
—
Prelude> :kind Int
Int :: *
—type constructors have more complex kinds:
Prelude> :kind (,)
(,) :: * -> * -> *
That means that (,)
takes 2 parameters and returns a type:
Prelude> :kind (,) Int String
(,) Int String :: *
A basic type can also be viewed as a zero-argument type constructor (analogous to how Haskell considers constants like True
that are members of an algebraic-data-type to be zero-argument data constructors).
An equivalent way of thinking about type constructors is as paramaterized data types, with a function similar to Vector< >
in C++/Java/C#.