Previous Up Next

10.10 Generalized algebraic datatypes

Generalized algebraic datatypes, or GADTs, extend usual sum types in two ways: constraints on type parameters may change depending on the value constructor, and some type variables may be existentially quantified. They are described in chapter 7.

(Introduced in OCaml 4.00)

constr-decl ::= ...
constr-name : [ constr-args -> ] typexpr
type-param ::= ...
[variance] _

Refutation cases. (Introduced in OCaml 4.03)

matching-case ::= pattern [when expr] -> expr
pattern -> .

Explicit naming of existentials. (Introduced in OCaml 4.13.0)

pattern ::= ...
constr ( type {typeconstr-name}+ ) ( pattern )

Previous Up Next