1.7 Coproduct types
Given A,B:π°, we introduce their coproduct type A+B:π°.
This corresponds to the disjoint union
in set theory
, and we may also use that name for it.
In type theory
, as was the case with functions and products
, the coproduct must be a fundamental construction, since there is no previously given notion of βunion of typesβ.
We also introduce a
nullary version: the empty type π:U.
There are two ways to construct elements of A+B, either as πππ (a):A+B for a:A, or as πππ(b):A+B for b:B. There are no ways to construct elements of the empty type.
To construct a non-dependent function f:A+BβC, we need functions g0:AβC and g1:BβC. Then f is defined via the defining equations
f(πππ (a)) | :β‘g0(a), | ||
f(πππ(b)) | :β‘g1(b). |
That is, the function f is defined by case analysis. As before, we can derive the recursor:
ππΎπΌA+B:β(C:π°)(AβC)β(BβC)βA+BβC |
with the defining equations
ππΎπΌA+B(C,g0,g1,πππ (a)) | :β‘g0(a), | ||
ππΎπΌA+B(C,g0,g1,πππ(b)) | :β‘g1(b). |
We can always construct a function f:πβC without having to give any defining equations, because there are no elements of π on which to define f. Thus, the recursor for π is
ππΎπΌπ:β(C:π°)πβC, |
which constructs the canonical function from the empty type to any other type. Logically, it corresponds to the principle ex falso quodlibet.
To construct a dependent function f:β(x:A+B)C(x) out of a coproduct, we assume as given the family C:(A+B)βπ°, and require
g0 | :βa:AC(πππ (a)), | ||
g1 | :βb:BC(πππ(b)). |
This yields f with the defining equations:
f(πππ (a)) | :β‘g0(a), | ||
f(πππ(b)) | :β‘g1(b). |
We package this scheme into the induction principle for coproducts:
πππ½A+B:β(C:(A+B)βπ°)(β(a:A)C(πππ (a)))β(β(b:B)C(πππ(b)))ββ(x:A+B)C(x). |
As before, the recursor arises in the case that the family C is constant.
The induction principle for the empty type
πππ½π:β(C:πβπ°)β(z:π)C(z) |
gives us a way to define a trivial dependent function out of the empty type.
Title | 1.7 Coproduct types |
---|---|
\metatable |