Definition
In Type Theory, a type constructor is an operation that builds new types from existing types. Type constructors take one or more types as parameters and produce a new type.
A type constructor can be viewed as a function at the type level: it maps types to types rather than values to values.
Examples
Nullary Type Constructors
Type constructors with no parameters are simply base types:
- : Natural numbers
- : Boolean values
Unary Type Constructors
Type constructors taking one type parameter:
- : Lists of elements of type
- : Optional values of type
- : Trees with nodes labeled by
Binary Type Constructors
Type constructors taking two type parameters:
- : Product Type of and
- : Sum Type of and
- : Function Type from to
Higher-Order Type Constructors
Type constructors can themselves take type constructors as arguments. For example, a functor or monad is a higher-order type constructor.
Dependent Type Constructors
In dependently typed language, type constructors can depend on values, not just types:
- : Vectors of type with length
- : Dependent Pair where is a type family indexed by
- : Dependent Function Type where the codomain depends on the input
Related Concepts
- Type Theory: The formal system in which type constructors are defined
- Product Type: A fundamental binary type constructor
- Sum Type: The dual to product types
- Function Type: Functions as a type constructor
- Dependent Pair: A generalization allowing dependency on values
- Kind: The type of a type constructor