The syntax for defining a variant uses the type declaration syntax.
type t =
| C1 of t1
| ...
| Cn of tn
Each variant needs to start with an uppercase letter:
(* bad *)
type t =
| example_value of int
File "[1]", line 3, characters 3-16:
3 | | example_value of int
^^^^^^^^^^^^^
Error: Syntax error
(* fixed *)
type t =
| Example_value of int
type t = Example_value of int
The of tn clause is optional, variants do not need to carry data.
The C1 part is called a "constructor," or sometimes a "tag."
We call a constructor "constant" if it carry data, and a constructor "non-constant" if it does not carry data.
If e ==> v, then C e ==> C v.
C e : t
if t = ... | C of t' | ...
and e : t'
C p is a pattern.