Redirected from "coproduct type".
Contents
Contents
Idea
In type theory a sum type of two types and (really: coproduct) is the type whose terms are either terms or terms .
In a model of the type theory in categorical semantics this is a distributive coproduct. In set theory, it is a disjoint union.
Definition
Like all type constructors in type theory, to characterize sum types we must specify how to build them, how to construct elements of them, how to use such elements, and the computation rules.
The way to build sum types is easy:
As a positive type
Sum types are most naturally presented as positive types, so that the constructor rules are primary. These say that we can obtain an element of from an element of , or from an element of .
The eliminator is derived from these: it says that in order to use an element of , it suffices to specify what should be done for the two ways in which that element could have been constructed.
The terms and can have free variables and respectively, but those variables become bound in the expression. In dependent type theory, we must generalize the eliminator to allow to depend on .
The beta reduction rules for a constructor followed by an eliminator:
The eta reduction rule for the opposite composite says that for any term in the context of ,
This says that if we unpack a term of type , but only use the resulting term of type or by way of packing them back into , then we might as well not have unpacked them to begin with. Note that choosing and , we obtain a simpler form of -conversion:
The positive presentation of sum types can be regarded as a particular sort of inductive type. In Coq syntax:
Inductive sum (A B:Type) : Type :=
| inl : A -> sum A B
| inr : B -> sum A B.
Coq implements the beta reduction rule, but not the eta (although eta equivalence is provable for the inductively defined identity types, using the dependent eliminator mentioned above).
As a negative type
It is possible to present sum types as negative types as well, but only if we allow sequents with multiple conclusions. This is common in sequent calculus presentations of classical logic, but not as common in type theory and almost unheard of in dependent type theory.
The two definitions are provably equivalent, but only using the contraction rule and the weakening rule. Thus, in linear logic they become distinct; the positive sum type is “plus” and the negative one is “par” .
With typal computation and uniqueness rules
Assuming that identification types, function types and dependent product types exist in the type theory, the sum type of types and is the inductive type generated by a function from to and a function from to :
Formation rules for sum types:
Introduction rules for sum types:
Elimination rules for sum types:
Computation rules for sum types:
Uniqueness rules for sum types:
The elimination, computation, and uniqueness rules for the sum type of and state that the sum type of and satisfy the dependent universal property of the sum type of and . If the dependent type theory also has dependent sum types and product types, allowing one to define the uniqueness quantifier, the dependent universal property of the sum type of of and could be simplified to the following rule:
In terms of dependent sum types and booleans
The sum type can be defined in terms of the boolean domain and the dependent sum type. Given types and , the sum type is defined as
Properties
Descent and large elimination
The descent for the sum type states that given any type families and one can construct a type family with families of equivalences of types
Large elimination for sum types strengthens the equivalences of types in descent to judgmental equality of types
References
A textbook account in the context of programming languages is in section 12 of
For sum types in homotopy type theory, see: