Legend:
Library
Module
Module type
Parameter
Class
Class type
type constant =
| Pconst_integer of string * char option(*

Integer constants such as 3 3l 3L 3n.

Suffixes [g-z][G-Z] are accepted by the parser. Suffixes except 'l', 'L' and 'n' are rejected by the typechecker

*)
| Pconst_char of char(*

Character such as 'c'.

*)
| Pconst_string of string * Location.t * string option(*

Constant string such as "constant" or {delim|other constant|delim}.

The location span the content of the string, without the delimiters.

*)
| Pconst_float of string * char option(*

Float constant such as 3.4, 2e5 or 1.4e-4.

Suffixes g-zG-Z are accepted by the parser. Suffixes are rejected by the typechecker.

*)
type location_stack = Location.t list

Extension points

type attribute = {
attr_name : string Asttypes.loc;
attr_payload : payload;
attr_loc : Location.t;
}

Attributes such as [\@id ARG] and [\@\@id ARG].

Metadata containers passed around within the AST. The compiler ignores unknown attributes.

and extension = string Asttypes.loc * payload

Extension points such as [%id ARG] and [%%id ARG].

Sub-language placeholder -- rejected by the typechecker.

and attributes = attribute list
and payload =
| PStr of structure
| PSig of signature(*

: SIG in an attribute or an extension point

*)
| PTyp of core_type(*

: T in an attribute or an extension point

*)
| PPat of pattern * expression option(*

? P or ? P when E, in an attribute or an extension point

*)

Core language

Type expressions

and core_type = {
ptyp_desc : core_type_desc;
ptyp_loc : Location.t;
ptyp_loc_stack : location_stack;
ptyp_attributes : attributes;(*

... [\@id1] [\@id2]

*)
}
and core_type_desc =
| Ptyp_any(*

_

*)
| Ptyp_var of string(*

A type variable such as 'a

*)
| Ptyp_arrow of Asttypes.arg_label * core_type * core_type(*

Ptyp_arrow(lbl, T1, T2) represents:

*)
| Ptyp_tuple of core_type list(*

Ptyp_tuple([T1 ; ... ; Tn]) represents a product type T1 * ... * Tn.

Invariant: n >= 2.

*)
| Ptyp_constr of Longident.t Asttypes.loc * core_type list(*

Ptyp_constr(lident, l) represents:

  • tconstr when l=[],
  • T tconstr when l=[T],
  • (T1, ..., Tn) tconstr when l=[T1 ; ... ; Tn].
*)
| Ptyp_object of object_field list * Asttypes.closed_flag(*

Ptyp_object([ l1:T1; ...; ln:Tn ], flag) represents:

  • < l1:T1; ...; ln:Tn > when flag is Closed,
  • < l1:T1; ...; ln:Tn; .. > when flag is Open.
*)
| Ptyp_class of Longident.t Asttypes.loc * core_type list(*

Ptyp_class(tconstr, l) represents:

  • #tconstr when l=[],
  • T #tconstr when l=[T],
  • (T1, ..., Tn) #tconstr when l=[T1 ; ... ; Tn].
*)
| Ptyp_alias of core_type * string(*

T as 'a.

*)
| Ptyp_variant of row_field list * Asttypes.closed_flag * Asttypes.label list option(*

Ptyp_variant([`A;`B], flag, labels) represents:

  • [ `A|`B ] when flag is Closed, and labels is None,
  • [> `A|`B ] when flag is Open, and labels is None,
  • [< `A|`B ] when flag is Closed, and labels is Some [],
  • [< `A|`B > `X `Y ] when flag is Closed, and labels is Some ["X";"Y"].
*)
| Ptyp_poly of string Asttypes.loc list * core_type(*

'a1 ... 'an. T

Can only appear in the following context:

  • As the core_type of a Ppat_constraint node corresponding to a constraint on a let-binding:

    let x : 'a1 ... 'an. T = e ...
*)
| Ptyp_package of package_type(*

(module S).

*)
| Ptyp_extension of extension(*

[%id].

*)

As package_type typed values:

  • (S, []) represents (module S),
  • (S, [(t1, T1) ; ... ; (tn, Tn)]) represents (module S with type t1 = T1 and ... and tn = Tn).
and row_field = {
prf_desc : row_field_desc;
prf_loc : Location.t;
prf_attributes : attributes;
}
and row_field_desc =
| Rtag of Asttypes.label Asttypes.loc * bool * core_type list(*

Rtag(`A, b, l) represents:

  • `A when b is true and l is [],
  • `A of T when b is false and l is [T],
  • `A of T1 & .. & Tn when b is false and l is [T1;...Tn],
  • `A of & T1 & .. & Tn when b is true and l is [T1;...Tn].
  • The bool field is true if the tag contains a constant (empty) constructor.
  • & occurs when several types are used for the same constructor (see 4.2 in the manual)
*)
| Rinherit of core_type(*

[ | t ]

*)
and object_field = {
pof_desc : object_field_desc;
pof_loc : Location.t;
pof_attributes : attributes;
}
and object_field_desc =
| Otag of Asttypes.label Asttypes.loc * core_type
| Oinherit of core_type

Patterns

and pattern = {
ppat_desc : pattern_desc;
ppat_loc : Location.t;
ppat_loc_stack : location_stack;
ppat_attributes : attributes;(*

... [\@id1] [\@id2]

*)
}
and pattern_desc =
| Ppat_any(*

The pattern _.

*)
| Ppat_var of string Asttypes.loc(*

A variable pattern such as x

*)
| Ppat_alias of pattern * string Asttypes.loc(*

An alias pattern such as P as 'a

*)
| Ppat_constant of constant(*

Patterns such as 1, 'a', "true", 1.0, 1l, 1L, 1n

*)
| Ppat_interval of constant * constant(*

Patterns such as 'a'..'z'.

Other forms of interval are recognized by the parser but rejected by the type-checker.

*)
| Ppat_tuple of pattern list(*

Patterns (P1, ..., Pn).

Invariant: n >= 2

*)
| Ppat_construct of Longident.t Asttypes.loc * (string Asttypes.loc list * pattern) option(*

Ppat_construct(C, args) represents:

  • C when args is None,
  • C P when args is Some ([], P)
  • C (P1, ..., Pn) when args is Some ([], Ppat_tuple [P1; ...; Pn])
  • C (type a b) P when args is Some ([a; b], P)
*)
| Ppat_variant of Asttypes.label * pattern option(*

Ppat_variant(`A, pat) represents:

  • `A when pat is None,
  • `A P when pat is Some P
*)
| Ppat_record of (Longident.t Asttypes.loc * pattern) list * Asttypes.closed_flag(*

Ppat_record([(l1, P1) ; ... ; (ln, Pn)], flag) represents:

  • { l1=P1; ...; ln=Pn } when flag is Closed
  • { l1=P1; ...; ln=Pn; _} when flag is Open

Invariant: n > 0

*)
| Ppat_array of pattern list(*

Pattern [| P1; ...; Pn |]

*)
| Ppat_or of