sum type

**natural deduction** metalanguage, practical foundations

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

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

In type theory a *sum type* of two types $A$ and $B$ is the type whose terms are either terms $a\colon A$ or terms $b\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:

$\frac{A\colon Type \qquad B\colon Type}{A+B \colon 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+B$ from an element of $A$, or from an element of $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+B$, it suffices to specify what should be done for the two ways in which that element could have been constructed.

$\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_A$ and $c_B$ can have free variables $x$ and $y$ respectively, but those variables become bound in the $match$ expression. In dependent type theory, we must generalize the eliminator to allow $C$ to depend on $A+B$.

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

$\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\colon C$ in the context of $p\colon A+B$,

$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+B$, but only use the resulting term of type $A$ or $B$ by way of packing them back into $A+B$, then we might as well not have unpacked them to begin with. Note that choosing $C\coloneqq A+B$ and $c \coloneqq z$, we obtain a simpler form of $\eta$-conversion:

$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).

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

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

Revised on December 4, 2012 21:54:59
by Urs Schreiber
(131.174.40.191)