In the ocaml language specification, there’s a short section:
poly-typexpr ::= typexpr
| { ' ident }+ . typexpr
There’s no explanation in the text, and the only instance of poly-typexpr is in defining a method type:
method-type ::= method-name : poly-typexpr
What does this allow me to do?
poly-typexpris also allowed as the type of a record field (see Section 6.8.1). These are commonly called “existential types,” though there is some debate on that point. Using a polymorphic type in this way changes the scope of the type variable. For example, compare the types:tis really a family of types, one for each possible value of'a. Each value of type'a tmust have a fieldfwith the type'a -> int. For example:In comparison,
uis a single type. Each value of typeumust have a fieldgwith the type'a -> intfor any'a. For example:Note here that
gdoesn’t depend on the type of its input at all; if it did, it wouldn’t have the type'a. 'a -> int. For example: