Callback. Binary sums in OCaml [01HI]
In OCaml, the binary sum of two types can be implemented as follows:
type ('a, 'b) coprod =
| Inl of 'a
| Inr of 'bThen the sum of two types s,t is written (s, t) coprod. Given x:s we may construct Inl x : (s, t) coprod, and similarly given y:t we may construct Inr y : (s, t) coprod.
We may use an element z : (s, t) coprod to produce an element of type r by case analysis:
match z with | Inl x -> (* use x:s to produce an element of r *) | Inl y -> (* use y:t to produce an element of r *)