Encoding. Binary sums/coproducts › Formation [01GI]
We wish to encode the following formation rule:
\frac { A,B~\mathit {type} }{ A+B~\mathit {type} }To that end, we define:
A+B :\equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(l:\mathsf {bool})}}\mathsf {If}(l;A;B)This is similar to the idea of a tagged union in C-like languages: we pair a label with the data that it refers to. Unlike in C, the type system keeps track for us of what sort of data can appear paired with what tag: this shows that C should have been dependently typed.