sum type


Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory

logiccategory theorytype theory
trueterminal object/(-2)-truncated objecth-level 0-type/unit type
falseinitial objectempty type
proposition(-1)-truncated objecth-proposition, mere proposition
proofgeneralized elementprogram
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
cut elimination for implicationcounit for hom-tensor adjunctionbeta reduction
introduction rule for implicationunit for hom-tensor adjunctioneta conversion
logical conjunctionproductproduct type
disjunctioncoproduct ((-1)-truncation of)sum type (bracket type of)
implicationinternal homfunction type
negationinternal hom into initial objectfunction type into empty type
universal quantificationdependent productdependent product type
existential quantificationdependent sum ((-1)-truncation of)dependent sum type (bracket type of)
equivalencepath space objectidentity type/path type
equivalence classquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
completely presented setdiscrete object/0-truncated objecth-level 2-type/preset/h-set
setinternal 0-groupoidBishop set/setoid
universeobject classifiertype of types
modalityclosure operator, (idempotent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels




In type theory a sum type of two types AA and BB is the type whose terms are either terms a:Aa\colon A or terms b:Bb\colon B.

In a model of the type theory in categorical semantics this is a coproduct. In set theory, it is a disjoint union.


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:

A:TypeB:TypeA+B:Type \frac{A\colon Type \qquad B\colon Type}{A+B \colon Type}

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 A+BA+B from an element of AA, or from an element of BB.

a:Ainl(a):A+Bb:Binr(b):A+B \frac{a\colon A}{inl(a)\colon A+B} \qquad \frac{b\colon B}{inr(b)\colon A+B}

The eliminator is derived from these: it says that in order to use an element of A+BA+B, it suffices to specify what should be done for the two ways in which that element could have been constructed.

p:A+Bx:Ac A:Cy:Bc B:Cmatch(p,x.c A,y.c B):C \frac{p\colon A+B \qquad x\colon A\vdash c_A\colon C \qquad y\colon B \vdash c_B\colon C}{match(p, x.c_A, y.c_B) \colon C}

The terms c Ac_A and c Bc_B can have free variables xx and yy respectively, but those variables become bound in the matchmatch expression. In dependent type theory, we must generalize the eliminator to allow CC to depend on A+BA+B.

The beta reduction rules for a constructor followed by an eliminator:

match(inl(a),x.c A,y.c B) βc A[a/x] match(inr(b),x.c A,y.c B) βc B[b/y] \begin{aligned} match(inl(a), x.c_A, y.c_B) &\to_\beta c_A[a/x]\\ match(inr(b), x.c_A, y.c_B) &\to_\beta c_B[b/y] \end{aligned}

The eta reduction rule for the opposite composite says that for any term c:Cc\colon C in the context of p:A+Bp\colon A+B,

match(p,x.c[inl(x)/z],y.c[inr(y)/z]) ηc[p/z].match(p, x.c[inl(x)/z], y.c[inr(y)/z]) \to_\eta c[p/z].

This says that if we unpack a term of type A+BA+B, but only use the resulting term of type AA or BB by way of packing them back into A+BA+B, then we might as well not have unpacked them to begin with. Note that choosing CA+BC\coloneqq A+B and czc \coloneqq z, we obtain a simpler form of η\eta-conversion:

match(p,x.inl(x),y.inr(y)) ηp.match(p, x.inl(x), y.inr(y)) \to_\eta p.

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” ABA\oplus B and the negative one is “par” ABA \parr B.


A textbook account in the context of programming languages is in section 12 of