---
name: "Parsetree"
section: "3o"
platform: "linux"
package: "ocaml"
version: "5.5.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Parsetree"
---

# Parsetree(3o)

Abstract syntax tree produced by parsing

## NAME

Parsetree - Abstract syntax tree produced by parsing

## Module

Module   Parsetree

## Documentation

Module **Parsetree**\
  :  **sig end**

Abstract syntax tree produced by parsing

Warning: this module is unstable and part of **Compiler\_libs** .

*type constant* = {\
  pconst\_desc :  **constant\_desc** ;\
  pconst\_loc :  **Location.t** ;\
  }

*type constant\_desc* =\
  \| 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-z** **G-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.

*type extension* =  **string Asttypes.loc \* payload**

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

Sub-language placeholder -- rejected by the typechecker.

*type attributes* =  **attribute list**

*type 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

*type core\_type* = {\
  ptyp\_desc :  **core\_type\_desc** ;\
  ptyp\_loc :  **Location.t** ;\
  ptyp\_loc\_stack :  **location\_stack** ;\
  ptyp\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type 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:

\- **T1 -\> T2** when  **lbl** is **Asttypes.arg\_label.Nolabel** ,

\- **~l:T1 -\> T2** when  **lbl** is **Asttypes.arg\_label.Labelled** ,

\- **?l:T1 -\> T2** when  **lbl** is **Asttypes.arg\_label.Optional** .

 \*)\
  \| Ptyp\_tuple **of** **(string option \* core\_type) list**   \
   (\*  **Ptyp\_tuple(tl)** represents a product type:

\- **T1 \* ... \* Tn** when  **tl** is  **(None, T1); ...; (None, Tn)**

\- **L1:T1 \* ... \* Ln:Tn** when  **tl** is  **(Some L1, T1); ...; (Some Ln, Tn)**

\-A mix, e.g.,  **L1:T1 \* T2** when  **tl** is  **(Some L1, T1); (None, T2)**

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 **Asttypes.closed\_flag.Closed** ,

\- **\< l1:T1; ...; ln:Tn; .. \>** when  **flag** is **Asttypes.closed\_flag.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 Asttypes.loc**   \
   (\*  **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  **Asttypes.closed\_flag.Closed** , and  **labels** is  **None** ,

\- **\[\> \`A\|\`B \]** when  **flag** is  **Asttypes.closed\_flag.Open** , and  **labels** is  **None** ,

\- **\[\< \`A\|\`B \]** when  **flag** is  **Asttypes.closed\_flag.Closed** , and  **labels** is  **Some \[\]** ,

\- **\[\< \`A\|\`B \> \`X \`Y \]** when  **flag** is  **Asttypes.closed\_flag.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  **Parsetree.core\_type** of a **Parsetree.pattern\_desc.Ppat\_constraint** node corresponding to a constraint on a let-binding:

```
let x : 'a1 ... 'an. T = e ...
```

\-Under  **Parsetree.class\_field\_kind.Cfk\_virtual** for methods (not values).

\-As the  **Parsetree.core\_type** of a **Parsetree.class\_type\_field\_desc.Pctf\_method** node.

\-As the  **Parsetree.core\_type** of a  **Parsetree.expression\_desc.Pexp\_poly** node.

\-As the  **Parsetree.label\_declaration.pld\_type** field of a **Parsetree.label\_declaration** .

\-As a  **Parsetree.core\_type** of a  **Parsetree.core\_type\_desc.Ptyp\_object** node.

\-As the  **Parsetree.value\_description.pval\_type** field of a **Parsetree.value\_description** .

 \*)\
  \| Ptyp\_package **of** **package\_type**   \
   (\*  **(module S)** .\
  \*)\
  \| Ptyp\_open **of** **Longident.t Asttypes.loc \* core\_type**   \
   (\*  **M.(T)**

 \*)\
  \| Ptyp\_extension **of** **extension**   \
   (\*  **\[%id\]** .\
  \*)\
  \| Ptyp\_functor **of** **Asttypes.arg\_label \* string Asttypes.loc \* package\_type** **\* core\_type**   \
   (\*  **(module M : S) -\> ...** : module-dependent arrow\
  \*)

*type package\_type* = {\
  ppt\_path :  **Longident.t Asttypes.loc** ;\
  ppt\_constraints :  **(Longident.t Asttypes.loc \* core\_type) list** ;\
  ppt\_loc :  **Location.t** ;\
  ppt\_attrs :  **attributes** ;\
  }

As  **Parsetree.package\_type** typed values:

\- **{ppt\_path: S; ppt\_constraints: \[\]}** represents  **(module S)** ,

\- **{ppt\_path: S; ppt\_constraints: \[(t1, T1) ; ... ; (tn, Tn)\]}** represents  **(module S with type t1 = T1 and ... and tn = Tn)** .

*type row\_field* = {\
  prf\_desc :  **row\_field\_desc** ;\
  prf\_loc :  **Location.t** ;\
  prf\_attributes :  **attributes** ;\
  }

*type 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 \]**

 \*)

*type object\_field* = {\
  pof\_desc :  **object\_field\_desc** ;\
  pof\_loc :  **Location.t** ;\
  pof\_attributes :  **attributes** ;\
  }

*type object\_field\_desc* =\
  \| Otag **of** **Asttypes.label Asttypes.loc \* core\_type**\
  \| Oinherit **of** **core\_type**

### Patterns

*type pattern* = {\
  ppat\_desc :  **pattern\_desc** ;\
  ppat\_loc :  **Location.t** ;\
  ppat\_loc\_stack :  **location\_stack** ;\
  ppat\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type 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** **(string option \* pattern) list \* Asttypes.closed\_flag**   \
   (\*  **Ppat\_tuple(pl, Closed)** represents

\- **(P1, ..., Pn)** when  **pl** is  **(None, P1); ...; (None, Pn)**

\- **(~L1:P1, ..., ~Ln:Pn)** when  **pl** is  **(Some L1, P1); ...; (Some Ln, Pn)**

\-A mix, e.g.  **(~L1:P1, P2)** when  **pl** is  **(Some L1, P1); (None, P2)**

**Ppat\_tuple(pl, Open)** is similar, but indicates the pattern additionally ends in a  **..** .

Invariant:

\-If Closed,  **n \>= 2** .

\-If Open,  **n \>= 1** .

 \*)\
  \| 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  **Asttypes.closed\_flag.Closed**

\- **{ l1=P1; ...; ln=Pn; \_}** when  **flag** is  **Asttypes.closed\_flag.Open**

Invariant:  **n \> 0**

 \*)\
  \| Ppat\_array **of** **pattern list**   \
   (\* Pattern  **\[\| P1; ...; Pn \|\]**

 \*)\
  \| Ppat\_or **of** **pattern \* pattern**   \
   (\* Pattern  **P1 \| P2**

 \*)\
  \| Ppat\_constraint **of** **pattern \* core\_type**   \
   (\* Pattern  **(P : T)**

 \*)\
  \| Ppat\_type **of** **Longident.t Asttypes.loc**   \
   (\* Pattern  **#tconst**

 \*)\
  \| Ppat\_lazy **of** **pattern**   \
   (\* Pattern  **lazy P**

 \*)\
  \| Ppat\_unpack **of** **string option Asttypes.loc \* package\_type option**   \
   (\*  **Ppat\_unpack(s, ptyp)** represents:

\- **(module P : S)** when  **s** is  **Some "P"** and  **ptyp** is  **Some "S"**

\- **(module \_ : S)** when  **s** is  **None** and  **ptyp** is  **Some "S"**

\- **(module P)** when  **s** is  **Some "P"** and  **ptyp** is  **None**

\- **(module \_)** when  **s** is  **None** and  **ptyp** is  **None**

 \*)\
  \| Ppat\_exception **of** **pattern**   \
   (\* Pattern  **exception P**

 \*)\
  \| Ppat\_effect **of** **pattern \* pattern**\
  \| Ppat\_extension **of** **extension**   \
   (\* Pattern  **\[%id\]**

 \*)\
  \| Ppat\_open **of** **Longident.t Asttypes.loc \* pattern**   \
   (\* Pattern  **M.(P)**

 \*)

### Value expressions

*type expression* = {\
  pexp\_desc :  **expression\_desc** ;\
  pexp\_loc :  **Location.t** ;\
  pexp\_loc\_stack :  **location\_stack** ;\
  pexp\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type expression\_desc* =\
  \| Pexp\_ident **of** **Longident.t Asttypes.loc**   \
   (\* Identifiers such as  **x** and  **M.x**

 \*)\
  \| Pexp\_constant **of** **constant**   \
   (\* Expressions constant such as  **1** ,  **'a'** ,  **"true"** ,  **1.0** ,  **1l** , **1L** ,  **1n**

 \*)\
  \| Pexp\_let **of** **Asttypes.rec\_flag \* value\_binding list \* expression**   \
   (\*  **Pexp\_let(flag, \[(P1,E1) ; ... ; (Pn,En)\], E)** represents:

\- **let P1 = E1 and ... and Pn = EN in E** when  **flag** is  **Asttypes.rec\_flag.Nonrecursive** ,

\- **let rec P1 = E1 and ... and Pn = EN in E** when  **flag** is  **Asttypes.rec\_flag.Recursive** .

 \*)\
  \| Pexp\_function **of** **function\_param list \* type\_constraint option** **\* function\_body**   \
   (\*  **Pexp\_function (\[P1; ...; Pn\], C, body)** represents any construct involving  **fun** or  **function** , including:

\- **fun P1 ... Pn -\> E** when  **body = Pfunction\_body E**

\- **fun P1 ... Pn -\> function p1 -\> e1 \| ... \| pm -\> em** when  **body = Pfunction\_cases \[ p1 -\> e1; ...; pm -\> em \]**

**C** represents a type constraint or coercion placed immediately before the arrow, e.g.  **fun P1 ... Pn : ty -\> ...** when  **C = Some (Pconstraint ty)** .

A function must have parameters: in  **Pexp\_function (params, \_, body)** , if  **params** does not contain a  **Pparam\_val \_** ,  **body** must be **Pfunction\_cases \_** .\
  \*)\
  \| Pexp\_apply **of** **expression \* (Asttypes.arg\_label \* expression) list**   \
   (\*  **Pexp\_apply(E0, \[(l1, E1) ; ... ; (ln, En)\])** represents  **E0 ~l1:E1 ... ~ln:En**

**li** can be **Asttypes.arg\_label.Nolabel** (non labeled argument), **Asttypes.arg\_label.Labelled** (labelled arguments) or **Asttypes.arg\_label.Optional** (optional argument).

Invariant:  **n \> 0**

 \*)\
  \| Pexp\_match **of** **expression \* case list**   \
   (\*  **match E0 with P1 -\> E1 \| ... \| Pn -\> En**

 \*)\
  \| Pexp\_try **of** **expression \* case list**   \
   (\*  **try E0 with P1 -\> E1 \| ... \| Pn -\> En**

 \*)\
  \| Pexp\_tuple **of** **(string option \* expression) list**   \
   (\*  **Pexp\_tuple(el)** represents

\- **(E1, ..., En)** when  **el** is  **(None, E1); ...; (None, En)**

\- **(~L1:E1, ..., ~Ln:En)** when  **el** is  **(Some L1, E1); ...; (Some Ln, En)**

\-A mix, e.g.,  **(~L1:E1, E2)** when  **el** is  **(Some L1, E1); (None, E2)**

Invariant:  **n \>= 2**

 \*)\
  \| Pexp\_construct **of** **Longident.t Asttypes.loc \* expression option**   \
   (\*  **Pexp\_construct(C, exp)** represents:

\- **C** when  **exp** is  **None** ,

\- **C E** when  **exp** is  **Some E** ,

\- **C (E1, ..., En)** when  **exp** is  **Some (Pexp\_tuple\[E1;...;En\])**

 \*)\
  \| Pexp\_variant **of** **Asttypes.label \* expression option**   \
   (\*  **Pexp\_variant(\`A, exp)** represents

\- **\`A** when  **exp** is  **None**

\- **\`A E** when  **exp** is  **Some E**

 \*)\
  \| Pexp\_record **of** **(Longident.t Asttypes.loc \* expression) list** **\* expression option**   \
   (\*  **Pexp\_record(\[(l1,P1) ; ... ; (ln,Pn)\], exp0)** represents

\- **{ l1=P1; ...; ln=Pn }** when  **exp0** is  **None**

\- **{ E0 with l1=P1; ...; ln=Pn }** when  **exp0** is  **Some E0**

Invariant:  **n \> 0**

 \*)\
  \| Pexp\_field **of** **expression \* Longident.t Asttypes.loc**   \
   (\*  **E.l**

 \*)\
  \| Pexp\_setfield **of** **expression \* Longident.t Asttypes.loc \* expression**   \
   (\*  **E1.l \<- E2**

 \*)\
  \| Pexp\_array **of** **expression list**   \
   (\*  **\[\| E1; ...; En \|\]**

 \*)\
  \| Pexp\_ifthenelse **of** **expression \* expression \* expression option**   \
   (\*  **if E1 then E2 else E3**

 \*)\
  \| Pexp\_sequence **of** **expression \* expression**   \
   (\*  **E1; E2**

 \*)\
  \| Pexp\_while **of** **expression \* expression**   \
   (\*  **while E1 do E2 done**

 \*)\
  \| Pexp\_for **of** **pattern \* expression \* expression** **\* Asttypes.direction\_flag \* expression**   \
   (\*  **Pexp\_for(i, E1, E2, direction, E3)** represents:

\- **for i = E1 to E2 do E3 done** when  **direction** is  **Asttypes.direction\_flag.Upto**

\- **for i = E1 downto E2 do E3 done** when  **direction** is  **Asttypes.direction\_flag.Downto**

 \*)\
  \| Pexp\_constraint **of** **expression \* core\_type**   \
   (\*  **(E : T)**

 \*)\
  \| Pexp\_coerce **of** **expression \* core\_type option \* core\_type**   \
   (\*  **Pexp\_coerce(E, from, T)** represents

\- **(E :\> T)** when  **from** is  **None** ,

\- **(E : T0 :\> T)** when  **from** is  **Some T0** .

 \*)\
  \| Pexp\_send **of** **expression \* Asttypes.label Asttypes.loc**   \
   (\*  **E # m**

 \*)\
  \| Pexp\_new **of** **Longident.t Asttypes.loc**   \
   (\*  **new M.c**

 \*)\
  \| Pexp\_setinstvar **of** **Asttypes.label Asttypes.loc \* expression**   \
   (\*  **x \<- 2**

 \*)\
  \| Pexp\_override **of** **(Asttypes.label Asttypes.loc \* expression) list**   \
   (\*  **{\< x1 = E1; ...; xn = En \>}**

 \*)\
  \| Pexp\_struct\_item **of** **structure\_item \* expression**   \
   (\*  **let SI in E**

 \*)\
  \| Pexp\_assert **of** **expression**   \
   (\*  **assert E** .

Note:  **assert false** is treated in a special way by the type-checker.\
  \*)\
  \| Pexp\_lazy **of** **expression**   \
   (\*  **lazy E**

 \*)\
  \| Pexp\_poly **of** **expression \* core\_type option**   \
   (\* Used for method bodies.

Can only be used as the expression under **Parsetree.class\_field\_kind.Cfk\_concrete** for methods (not values).\
  \*)\
  \| Pexp\_object **of** **class\_structure**   \
   (\*  **object ... end**

 \*)\
  \| Pexp\_newtype **of** **string Asttypes.loc \* expression**   \
   (\*  **fun (type t) -\> E**

 \*)\
  \| Pexp\_pack **of** **module\_expr \* package\_type option**   \
   (\*  **(module ME)** or  **(module ME : S)** .\
  \*)\
  \| Pexp\_letop **of** **letop**   \
   (\* -  **let\* P = E0 in E1**

\- **let\* P0 = E00 and\* P1 = E01 in E1**

 \*)\
  \| Pexp\_extension **of** **extension**   \
   (\*  **\[%id\]**

 \*)\
  \| Pexp\_unreachable  (\*  **.**

 \*)

*type case* = {\
  pc\_lhs :  **pattern** ;\
  pc\_guard :  **expression option** ;\
  pc\_rhs :  **expression** ;\
  }

Values of type  **Parsetree.case** represents  **(P -\> E)** or  **(P when E0 -\> E)**

*type letop* = {\
  let\_ :  **binding\_op** ;\
  ands :  **binding\_op list** ;\
  body :  **expression** ;\
  }

*type binding\_op* = {\
  pbop\_op :  **string Asttypes.loc** ;\
  pbop\_pat :  **pattern** ;\
  pbop\_exp :  **expression** ;\
  pbop\_loc :  **Location.t** ;\
  }

*type function\_param\_desc* =\
  \| Pparam\_val **of** **Asttypes.arg\_label \* expression option \* pattern**   \
   (\*  **Pparam\_val (lbl, exp0, P)** represents the parameter:

\- **P** when  **lbl** is  **Asttypes.arg\_label.Nolabel** and  **exp0** is  **None**

\- **~l:P** when  **lbl** is  **Asttypes.arg\_label.Labelled** and  **exp0** is  **None**

\- **?l:P** when  **lbl** is  **Asttypes.arg\_label.Optional** and  **exp0** is  **None**

\- **?l:(P = E0)** when  **lbl** is  **Asttypes.arg\_label.Optional** and  **exp0** is  **Some E0**

Note: If  **E0** is provided, only **Asttypes.arg\_label.Optional** is allowed.\
  \*)\
  \| Pparam\_newtype **of** **string Asttypes.loc**   \
   (\*  **Pparam\_newtype x** represents the parameter  **(type x)** . **x** carries the location of the identifier, whereas the  **pparam\_loc** on the enclosing  **function\_param** node is the location of the  **(type x)** as a whole.

Multiple parameters  **(type a b c)** are represented as multiple **Pparam\_newtype** nodes, let's say:

```
[ { pparam_kind = Pparam_newtype a; pparam_loc = loc1 };
           { pparam_kind = Pparam_newtype b; pparam_loc = loc2 };
           { pparam_kind = Pparam_newtype c; pparam_loc = loc3 };
         ]

```

Here, the first loc  **loc1** is the location of  **(type a b c)** , and the subsequent locs  **loc2** and  **loc3** are the same as  **loc1** , except marked as ghost locations. The locations on  **a** ,  **b** ,  **c** , correspond to the variables  **a** ,  **b** , and  **c** in the source code.\
  \*)

*type function\_param* = {\
  pparam\_loc :  **Location.t** ;\
  pparam\_desc :  **function\_param\_desc** ;\
  }

*type function\_body* =\
  \| Pfunction\_body **of** **expression**\
  \| Pfunction\_cases **of** **case list \* Location.t \* attributes**   \
   (\* In  **Pfunction\_cases (\_, loc, attrs)** , the location extends from the start of the  **function** keyword to the end of the last case. The compiler will only use typechecking-related attributes from  **attrs** , e.g. enabling or disabling a warning.\
  \*)

See the comment on  **Parsetree.expression\_desc.Pexp\_function** .

*type type\_constraint* =\
  \| Pconstraint **of** **core\_type**\
  \| Pcoerce **of** **core\_type option \* core\_type**   \
   (\* See the comment on  **Parsetree.expression\_desc.Pexp\_function** .\
  \*)

### Value descriptions

*type value\_description* = {\
  pval\_name :  **string Asttypes.loc** ;\
  pval\_type :  **core\_type** ;\
  pval\_prim :  **string list** ;\
  pval\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  pval\_loc :  **Location.t** ;\
  }

Values of type  **Parsetree.value\_description** represents:

\- **val x: T** , when  **Parsetree.value\_description.pval\_prim** is  **\[\]**

\- **external x: T = "s1" ... "sn"** when  **Parsetree.value\_description.pval\_prim** is  **\["s1";..."sn"\]**

### Type declarations

*type type\_declaration* = {\
  ptype\_name :  **string Asttypes.loc** ;\
  ptype\_params :  **(core\_type \* (Asttypes.variance \* Asttypes.injectivity)) list** ;  (\*  **('a1,...'an) t**

 \*) \
  ptype\_constraints :  **(core\_type \* core\_type \* Location.t) list** ;  (\*  **... constraint T1=T1'  ... constraint Tn=Tn'**

 \*) \
  ptype\_kind :  **type\_kind** ;\
  ptype\_private :  **Asttypes.private\_flag** ;  (\* for  **= private ...**

 \*) \
  ptype\_manifest :  **core\_type option** ;  (\* represents  **= T**

 \*) \
  ptype\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  ptype\_loc :  **Location.t** ;\
  }

Here are type declarations and their representation, for various  **Parsetree.type\_declaration.ptype\_kind** and  **Parsetree.type\_declaration.ptype\_manifest** values:

\- **type t** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_abstract** , and  **manifest** is  **None** ,

\- **type t = T0** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_abstract** , and  **manifest** is  **Some T0** ,

\- **type t = C of T \| ...** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_variant** , and  **manifest** is  **None** ,

\- **type t = T0 = C of T \| ...** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_variant** , and  **manifest** is  **Some T0** ,

\- **type t = {l: T; ...}** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_record** , and  **manifest** is  **None** ,

\- **type t = T0 = {l : T; ...}** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_record** , and  **manifest** is  **Some T0** ,

\- **type t = ..** when  **type\_kind** is  **Parsetree.type\_kind.Ptype\_open** , and  **manifest** is  **None** .

\- **type t = external "gmp"** when  **type\_kind** is **Parsetree.type\_kind.Ptype\_external** and  **manifest** is  **None** .

*type type\_kind* =\
  \| Ptype\_abstract\
  \| Ptype\_variant **of** **constructor\_declaration list**\
  \| Ptype\_record **of** **label\_declaration list**   \
   (\* Invariant: non-empty list\
  \*)\
  \| Ptype\_open\
  \| Ptype\_external **of** **string**

*type label\_declaration* = {\
  pld\_name :  **string Asttypes.loc** ;\
  pld\_mutable :  **Asttypes.mutable\_flag** ;\
  pld\_type :  **core\_type** ;\
  pld\_loc :  **Location.t** ;\
  pld\_attributes :  **attributes** ;  (\*  **l : T \[@id1\] \[@id2\]**

 \*) \
  }

\-  **{ ...; l: T; ... }** when  **Parsetree.label\_declaration.pld\_mutable** is  **Asttypes.mutable\_flag.Immutable** ,

\- **{ ...; mutable l: T; ... }** when  **Parsetree.label\_declaration.pld\_mutable** is  **Asttypes.mutable\_flag.Mutable** .

Note:  **T** can be a  **Parsetree.core\_type\_desc.Ptyp\_poly** .

*type constructor\_declaration* = {\
  pcd\_name :  **string Asttypes.loc** ;\
  pcd\_vars :  **string Asttypes.loc list** ;\
  pcd\_args :  **constructor\_arguments** ;\
  pcd\_res :  **core\_type option** ;\
  pcd\_loc :  **Location.t** ;\
  pcd\_attributes :  **attributes** ;  (\*  **C of ... \[@id1\] \[@id2\]**

 \*) \
  }

*type constructor\_arguments* =\
  \| Pcstr\_tuple **of** **core\_type list**\
  \| Pcstr\_record **of** **label\_declaration list**   \
   (\* Values of type  **Parsetree.constructor\_declaration** represents the constructor arguments of:

\- **C of T1 \* ... \* Tn** when  **res = None** , and  **args = Pcstr\_tuple \[T1; ... ; Tn\]** ,

\- **C: T0** when  **res = Some T0** , and  **args = Pcstr\_tuple \[\]** ,

\- **C: T1 \* ... \* Tn -\> T0** when  **res = Some T0** , and  **args = Pcstr\_tuple \[T1; ... ; Tn\]** ,

\- **C of {...}** when  **res = None** , and  **args = Pcstr\_record \[...\]** ,

\- **C: {...} -\> T0** when  **res = Some T0** , and  **args = Pcstr\_record \[...\]** .

 \*)

*type type\_extension* = {\
  ptyext\_path :  **Longident.t Asttypes.loc** ;\
  ptyext\_params :  **(core\_type \* (Asttypes.variance \* Asttypes.injectivity)) list** ;\
  ptyext\_constructors :  **extension\_constructor list** ;\
  ptyext\_private :  **Asttypes.private\_flag** ;\
  ptyext\_loc :  **Location.t** ;\
  ptyext\_attributes :  **attributes** ;  (\* ...  **@@id1** **@@id2**

 \*) \
  }

Definition of new extensions constructors for the extensive sum type  **t** ( **type t += ...** ).

*type extension\_constructor* = {\
  pext\_name :  **string Asttypes.loc** ;\
  pext\_kind :  **extension\_constructor\_kind** ;\
  pext\_loc :  **Location.t** ;\
  pext\_attributes :  **attributes** ;  (\*  **C of ... \[@id1\] \[@id2\]**

 \*) \
  }

*type type\_exception* = {\
  ptyexn\_constructor :  **extension\_constructor** ;\
  ptyexn\_loc :  **Location.t** ;\
  ptyexn\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  }

Definition of a new exception ( **exception E** ).

*type extension\_constructor\_kind* =\
  \| Pext\_decl **of** **string Asttypes.loc list \* constructor\_arguments** **\* core\_type option**   \
   (\*  **Pext\_decl(existentials, c\_args, t\_opt)** describes a new extension constructor. It can be:

\- **C of T1 \* ... \* Tn** when:

\- **existentials** is  **\[\]** ,

\- **c\_args** is  **\[T1; ...; Tn\]** ,

\- **t\_opt** is  **None**

\- **C: T0** when

\- **existentials** is  **\[\]** ,

\- **c\_args** is  **\[\]** ,

\- **t\_opt** is  **Some T0** .

\- **C: T1 \* ... \* Tn -\> T0** when

\- **existentials** is  **\[\]** ,

\- **c\_args** is  **\[T1; ...; Tn\]** ,

\- **t\_opt** is  **Some T0** .

\- **C: 'a... . T1 \* ... \* Tn -\> T0** when

\- **existentials** is  **\['a;...\]** ,

\- **c\_args** is  **\[T1; ... ; Tn\]** ,

\- **t\_opt** is  **Some T0** .

 \*)\
  \| Pext\_rebind **of** **Longident.t Asttypes.loc**   \
   (\*  **Pext\_rebind(D)** re-export the constructor  **D** with the new name  **C**

 \*)

### Class language

### Type expressions for the class language

*type class\_type* = {\
  pcty\_desc :  **class\_type\_desc** ;\
  pcty\_loc :  **Location.t** ;\
  pcty\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type class\_type\_desc* =\
  \| Pcty\_constr **of** **Longident.t Asttypes.loc \* core\_type list**   \
   (\* -  **c**

\- **\['a1, ..., 'an\] c**

 \*)\
  \| Pcty\_signature **of** **class\_signature**   \
   (\*  **object ... end**

 \*)\
  \| Pcty\_arrow **of** **Asttypes.arg\_label \* core\_type \* class\_type**   \
   (\*  **Pcty\_arrow(lbl, T, CT)** represents:

\- **T -\> CT** when  **lbl** is  **Asttypes.arg\_label.Nolabel** ,

\- **~l:T -\> CT** when  **lbl** is  **Asttypes.arg\_label.Labelled** ,

\- **?l:T -\> CT** when  **lbl** is  **Asttypes.arg\_label.Optional** .

 \*)\
  \| Pcty\_extension **of** **extension**   \
   (\*  **%id**

 \*)\
  \| Pcty\_open **of** **open\_description \* class\_type**   \
   (\*  **let open M in CT**

 \*)

*type class\_signature* = {\
  pcsig\_self :  **core\_type** ;\
  pcsig\_fields :  **class\_type\_field list** ;\
  }

Values of type  **class\_signature** represents:

\- **object('selfpat) ... end**

\- **object ... end** when  **Parsetree.class\_signature.pcsig\_self** is  **Parsetree.core\_type\_desc.Ptyp\_any**

*type class\_type\_field* = {\
  pctf\_desc :  **class\_type\_field\_desc** ;\
  pctf\_loc :  **Location.t** ;\
  pctf\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  }

*type class\_type\_field\_desc* =\
  \| Pctf\_inherit **of** **class\_type**   \
   (\*  **inherit CT**

 \*)\
  \| Pctf\_val **of** **(Asttypes.label Asttypes.loc \* Asttypes.mutable\_flag \*** **Asttypes.virtual\_flag \* core\_type)**   \
   (\*  **val x: T**

 \*)\
  \| Pctf\_method **of** **(Asttypes.label Asttypes.loc \* Asttypes.private\_flag \*** **Asttypes.virtual\_flag \* core\_type)**   \
   (\*  **method x: T**

Note:  **T** can be a  **Parsetree.core\_type\_desc.Ptyp\_poly** .\
  \*)\
  \| Pctf\_constraint **of** **(core\_type \* core\_type)**   \
   (\*  **constraint T1 = T2**

 \*)\
  \| Pctf\_attribute **of** **attribute**   \
   (\*  **\[@@@id\]**

 \*)\
  \| Pctf\_extension **of** **extension**   \
   (\*  **\[%%id\]**

 \*)

*type* **'a** *class\_infos* = {\
  pci\_virt :  **Asttypes.virtual\_flag** ;\
  pci\_params :  **(core\_type \* (Asttypes.variance \* Asttypes.injectivity)) list** ;\
  pci\_name :  **string Asttypes.loc** ;\
  pci\_expr :  **'a** ;\
  pci\_loc :  **Location.t** ;\
  pci\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  }

Values of type  **class\_expr class\_infos** represents:

\- **class c = ...**

\- **class \['a1,...,'an\] c = ...**

\- **class virtual c = ...**

They are also used for "class type" declaration.

*type class\_description* =  **class\_type class\_infos**

*type class\_type\_declaration* =  **class\_type class\_infos**

### Value expressions for the class language

*type class\_expr* = {\
  pcl\_desc :  **class\_expr\_desc** ;\
  pcl\_loc :  **Location.t** ;\
  pcl\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type class\_expr\_desc* =\
  \| Pcl\_constr **of** **Longident.t Asttypes.loc \* core\_type list**   \
   (\*  **c** and  **\['a1, ..., 'an\] c**

 \*)\
  \| Pcl\_structure **of** **class\_structure**   \
   (\*  **object ... end**

 \*)\
  \| Pcl\_fun **of** **Asttypes.arg\_label \* expression option \* pattern** **\* class\_expr**   \
   (\*  **Pcl\_fun(lbl, exp0, P, CE)** represents:

\- **fun P -\> CE** when  **lbl** is  **Asttypes.arg\_label.Nolabel** and  **exp0** is  **None** ,

\- **fun ~l:P -\> CE** when  **lbl** is  **Asttypes.arg\_label.Labelled** and  **exp0** is  **None** ,

\- **fun ?l:P -\> CE** when  **lbl** is  **Asttypes.arg\_label.Optional** and  **exp0** is  **None** ,

\- **fun ?l:(P = E0) -\> CE** when  **lbl** is  **Asttypes.arg\_label.Optional** and  **exp0** is  **Some E0** .

 \*)\
  \| Pcl\_apply **of** **class\_expr \* (Asttypes.arg\_label \* expression) list**   \
   (\*  **Pcl\_apply(CE, \[(l1,E1) ; ... ; (ln,En)\])** represents  **CE ~l1:E1 ... ~ln:En** . **li** can be empty (non labeled argument) or start with  **?** (optional argument).

Invariant:  **n \> 0**

 \*)\
  \| Pcl\_let **of** **Asttypes.rec\_flag \* value\_binding list \* class\_expr**   \
   (\*  **Pcl\_let(rec, \[(P1, E1); ... ; (Pn, En)\], CE)** represents:

\- **let P1 = E1 and ... and Pn = EN in CE** when  **rec** is  **Asttypes.rec\_flag.Nonrecursive** ,

\- **let rec P1 = E1 and ... and Pn = EN in CE** when  **rec** is  **Asttypes.rec\_flag.Recursive** .

 \*)\
  \| Pcl\_constraint **of** **class\_expr \* class\_type**   \
   (\*  **(CE : CT)**

 \*)\
  \| Pcl\_extension **of** **extension**   \
   (\*  **\[%id\]**

 \*)\
  \| Pcl\_open **of** **open\_description \* class\_expr**   \
   (\*  **let open M in CE**

 \*)

*type class\_structure* = {\
  pcstr\_self :  **pattern** ;\
  pcstr\_fields :  **class\_field list** ;\
  }

Values of type  **Parsetree.class\_structure** represents:

\- **object(selfpat) ... end**

\- **object ... end** when  **Parsetree.class\_structure.pcstr\_self** is  **Parsetree.pattern\_desc.Ppat\_any**

*type class\_field* = {\
  pcf\_desc :  **class\_field\_desc** ;\
  pcf\_loc :  **Location.t** ;\
  pcf\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  }

*type class\_field\_desc* =\
  \| Pcf\_inherit **of** **Asttypes.override\_flag \* class\_expr \* string Asttypes.loc option**   \
   (\*  **Pcf\_inherit(flag, CE, s)** represents:

\- **inherit CE** when  **flag** is  **Asttypes.override\_flag.Fresh** and  **s** is  **None** ,

\- **inherit CE as x** when  **flag** is  **Asttypes.override\_flag.Fresh** and  **s** is  **Some x** ,

\- **inherit! CE** when  **flag** is  **Asttypes.override\_flag.Override** and  **s** is  **None** ,

\- **inherit! CE as x** when  **flag** is  **Asttypes.override\_flag.Override** and  **s** is  **Some x**

 \*)\
  \| Pcf\_val **of** **(Asttypes.label Asttypes.loc \* Asttypes.mutable\_flag \*** **class\_field\_kind)**   \
   (\*  **Pcf\_val(x,flag, kind)** represents:

\- **val x = E** when  **flag** is  **Asttypes.mutable\_flag.Immutable** and  **kind** is  **Parsetree.class\_field\_kind.Cfk\_concrete**

\- **val virtual x: T** when  **flag** is  **Asttypes.mutable\_flag.Immutable** and  **kind** is  **Parsetree.class\_field\_kind.Cfk\_virtual**

\- **val mutable x = E** when  **flag** is  **Asttypes.mutable\_flag.Mutable** and  **kind** is  **Parsetree.class\_field\_kind.Cfk\_concrete**

\- **val mutable virtual x: T** when  **flag** is  **Asttypes.mutable\_flag.Mutable** and  **kind** is  **Parsetree.class\_field\_kind.Cfk\_virtual**

 \*)\
  \| Pcf\_method **of** **(Asttypes.label Asttypes.loc \* Asttypes.private\_flag \*** **class\_field\_kind)**   \
   (\* -  **method x = E** ( **E** can be a  **Parsetree.expression\_desc.Pexp\_poly** )

\- **method virtual x: T** ( **T** can be a  **Parsetree.core\_type\_desc.Ptyp\_poly** )

 \*)\
  \| Pcf\_constraint **of** **(core\_type \* core\_type)**   \
   (\*  **constraint T1 = T2**

 \*)\
  \| Pcf\_initializer **of** **expression**   \
   (\*  **initializer E**

 \*)\
  \| Pcf\_attribute **of** **attribute**   \
   (\*  **\[@@@id\]**

 \*)\
  \| Pcf\_extension **of** **extension**   \
   (\*  **\[%%id\]**

 \*)

*type class\_field\_kind* =\
  \| Cfk\_virtual **of** **core\_type**\
  \| Cfk\_concrete **of** **Asttypes.override\_flag \* expression**

*type class\_declaration* =  **class\_expr class\_infos**

### Module language

### Type expressions for the module language

*type module\_type* = {\
  pmty\_desc :  **module\_type\_desc** ;\
  pmty\_loc :  **Location.t** ;\
  pmty\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type module\_type\_desc* =\
  \| Pmty\_ident **of** **Longident.t Asttypes.loc**   \
   (\*  **Pmty\_ident(S)** represents  **S**

 \*)\
  \| Pmty\_signature **of** **signature**   \
   (\*  **sig ... end**

 \*)\
  \| Pmty\_functor **of** **functor\_parameter \* module\_type**   \
   (\*  **functor(X : MT1) -\> MT2**

 \*)\
  \| Pmty\_with **of** **module\_type \* with\_constraint list**   \
   (\*  **MT with ...**

 \*)\
  \| Pmty\_typeof **of** **module\_expr**   \
   (\*  **module type of ME**

 \*)\
  \| Pmty\_extension **of** **extension**   \
   (\*  **\[%id\]**

 \*)\
  \| Pmty\_alias **of** **Longident.t Asttypes.loc**   \
   (\*  **(module M)**

 \*)

*type functor\_parameter* =\
  \| Unit  (\*  **()**

 \*)\
  \| Named **of** **string option Asttypes.loc \* module\_type**   \
   (\*  **Named(name, MT)** represents:

\- **(X : MT)** when  **name** is  **Some X** ,

\- **(\_ : MT)** when  **name** is  **None**

 \*)

*type signature* =  **signature\_item list**

*type signature\_item* = {\
  psig\_desc :  **signature\_item\_desc** ;\
  psig\_loc :  **Location.t** ;\
  }

*type signature\_item\_desc* =\
  \| Psig\_value **of** **value\_description**   \
   (\* -  **val x: T**

\- **external x: T = "s1" ... "sn"**

 \*)\
  \| Psig\_type **of** **Asttypes.rec\_flag \* type\_declaration list**   \
   (\*  **type t1 = ... and ... and tn  = ...**

 \*)\
  \| Psig\_typesubst **of** **type\_declaration list**   \
   (\*  **type t1 := ... and ... and tn := ...**

 \*)\
  \| Psig\_typext **of** **type\_extension**   \
   (\*  **type t1 += ...**

 \*)\
  \| Psig\_exception **of** **type\_exception**   \
   (\*  **exception C of T**

 \*)\
  \| Psig\_module **of** **module\_declaration**   \
   (\*  **module X = M** and  **module X : MT**

 \*)\
  \| Psig\_modsubst **of** **module\_substitution**   \
   (\*  **module X := M**

 \*)\
  \| Psig\_recmodule **of** **module\_declaration list**   \
   (\*  **module rec X1 : MT1 and ... and Xn : MTn**

 \*)\
  \| Psig\_modtype **of** **module\_type\_declaration**   \
   (\*  **module type S = MT** and  **module type S**

 \*)\
  \| Psig\_modtypesubst **of** **module\_type\_declaration**   \
   (\*  **module type S :=  ...**

 \*)\
  \| Psig\_open **of** **open\_description**   \
   (\*  **open X**

 \*)\
  \| Psig\_include **of** **include\_description**   \
   (\*  **include MT**

 \*)\
  \| Psig\_class **of** **class\_description list**   \
   (\*  **class c1 : ... and ... and cn : ...**

 \*)\
  \| Psig\_class\_type **of** **class\_type\_declaration list**   \
   (\*  **class type ct1 = ... and ... and ctn = ...**

 \*)\
  \| Psig\_attribute **of** **attribute**   \
   (\*  **\[@@@id\]**

 \*)\
  \| Psig\_extension **of** **extension \* attributes**   \
   (\*  **\[%%id\]**

 \*)

*type module\_declaration* = {\
  pmd\_name :  **string option Asttypes.loc** ;\
  pmd\_type :  **module\_type** ;\
  pmd\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  pmd\_loc :  **Location.t** ;\
  }

Values of type  **module\_declaration** represents  **S : MT**

*type module\_substitution* = {\
  pms\_name :  **string Asttypes.loc** ;\
  pms\_manifest :  **Longident.t Asttypes.loc** ;\
  pms\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  pms\_loc :  **Location.t** ;\
  }

Values of type  **module\_substitution** represents  **S := M**

*type module\_type\_declaration* = {\
  pmtd\_name :  **string Asttypes.loc** ;\
  pmtd\_type :  **module\_type option** ;\
  pmtd\_attributes :  **attributes** ;  (\*  **... \[@@id1\] \[@@id2\]**

 \*) \
  pmtd\_loc :  **Location.t** ;\
  }

Values of type  **module\_type\_declaration** represents:

\- **S = MT** ,

\- **S** for abstract module type declaration, when  **Parsetree.module\_type\_declaration.pmtd\_type** is  **None** .

*type* **'a** *open\_infos* = {\
  popen\_expr :  **'a** ;\
  popen\_override :  **Asttypes.override\_flag** ;\
  popen\_loc :  **Location.t** ;\
  popen\_attributes :  **attributes** ;\
  }

Values of type  **'a open\_infos** represents:

\- **open! X** when  **Parsetree.open\_infos.popen\_override** is  **Asttypes.override\_flag.Override** (silences the "used identifier shadowing" warning)

\- **open  X** when  **Parsetree.open\_infos.popen\_override** is  **Asttypes.override\_flag.Fresh**

*type open\_description* =  **Longident.t Asttypes.loc open\_infos**

Values of type  **open\_description** represents:

\- **open M.N**

\- **open M(N).O**

*type open\_declaration* =  **module\_expr open\_infos**

Values of type  **open\_declaration** represents:

\- **open M.N**

\- **open M(N).O**

\- **open struct ... end**

*type* **'a** *include\_infos* = {\
  pincl\_mod :  **'a** ;\
  pincl\_loc :  **Location.t** ;\
  pincl\_attributes :  **attributes** ;\
  }

*type include\_description* =  **module\_type include\_infos**

Values of type  **include\_description** represents  **include MT**

*type include\_declaration* =  **module\_expr include\_infos**

Values of type  **include\_declaration** represents  **include ME**

*type with\_constraint* =\
  \| Pwith\_type **of** **Longident.t Asttypes.loc \* type\_declaration**   \
   (\*  **with type X.t = ...**

Note: the last component of the longident must match the name of the type\_declaration.\
  \*)\
  \| Pwith\_module **of** **Longident.t Asttypes.loc \* Longident.t Asttypes.loc**   \
   (\*  **with module X.Y = Z**

 \*)\
  \| Pwith\_modtype **of** **Longident.t Asttypes.loc \* module\_type**   \
   (\*  **with module type X.Y = Z**

 \*)\
  \| Pwith\_modtypesubst **of** **Longident.t Asttypes.loc \* module\_type**   \
   (\*  **with module type X.Y := sig end**

 \*)\
  \| Pwith\_typesubst **of** **Longident.t Asttypes.loc \* type\_declaration**   \
   (\*  **with type X.t := ..., same format as \[Pwith\_type\]**

 \*)\
  \| Pwith\_modsubst **of** **Longident.t Asttypes.loc \* Longident.t Asttypes.loc**   \
   (\*  **with module X.Y := Z**

 \*)

### Value expressions for the module language

*type module\_expr* = {\
  pmod\_desc :  **module\_expr\_desc** ;\
  pmod\_loc :  **Location.t** ;\
  pmod\_attributes :  **attributes** ;  (\*  **... \[@id1\] \[@id2\]**

 \*) \
  }

*type module\_expr\_desc* =\
  \| Pmod\_ident **of** **Longident.t Asttypes.loc**   \
   (\*  **X**

 \*)\
  \| Pmod\_structure **of** **structure**   \
   (\*  **struct ... end**

 \*)\
  \| Pmod\_functor **of** **functor\_parameter \* module\_expr**   \
   (\*  **functor(X : MT1) -\> ME**

 \*)\
  \| Pmod\_apply **of** **module\_expr \* module\_expr**   \
   (\*  **ME1(ME2)**

 \*)\
  \| Pmod\_apply\_unit **of** **module\_expr**   \
   (\*  **ME1()**

 \*)\
  \| Pmod\_constraint **of** **module\_expr \* module\_type**   \
   (\*  **(ME : MT)**

 \*)\
  \| Pmod\_unpack **of** **expression**   \
   (\*  **(val E)**

 \*)\
  \| Pmod\_extension **of** **extension**   \
   (\*  **\[%id\]**

 \*)

*type structure* =  **structure\_item list**

*type structure\_item* = {\
  pstr\_desc :  **structure\_item\_desc** ;\
  pstr\_loc :  **Location.t** ;\
  }

*type structure\_item\_desc* =\
  \| Pstr\_eval **of** **expression \* attributes**   \
   (\*  **E**

 \*)\
  \| Pstr\_value **of** **Asttypes.rec\_flag \* value\_binding list**   \
   (\*  **Pstr\_value(rec, \[(P1, E1 ; ... ; (Pn, En))\])** represents:

\- **let P1 = E1 and ... and Pn = EN** when  **rec** is  **Asttypes.rec\_flag.Nonrecursive** ,

\- **let rec P1 = E1 and ... and Pn = EN**  when  **rec** is  **Asttypes.rec\_flag.Recursive** .

 \*)\
  \| Pstr\_primitive **of** **value\_description**   \
   (\* -  **val x: T**

\- **external x: T = "s1" ... "sn"**

 \*)\
  \| Pstr\_type **of** **Asttypes.rec\_flag \* type\_declaration list**   \
   (\*  **type t1 = ... and ... and tn = ...**

 \*)\
  \| Pstr\_typext **of** **type\_extension**   \
   (\*  **type t1 += ...**

 \*)\
  \| Pstr\_exception **of** **type\_exception**   \
   (\* -  **exception C of T**

\- **exception C = M.X**

 \*)\
  \| Pstr\_module **of** **module\_binding**   \
   (\*  **module X = ME**

 \*)\
  \| Pstr\_recmodule **of** **module\_binding list**   \
   (\*  **module rec X1 = ME1 and ... and Xn = MEn**

 \*)\
  \| Pstr\_modtype **of** **module\_type\_declaration**   \
   (\*  **module type S = MT**

 \*)\
  \| Pstr\_open **of** **open\_declaration**   \
   (\*  **open X**

 \*)\
  \| Pstr\_class **of** **class\_declaration list**   \
   (\*  **class c1 = ... and ... and cn = ...**

 \*)\
  \| Pstr\_class\_type **of** **class\_type\_declaration list**   \
   (\*  **class type ct1 = ... and ... and ctn = ...**

 \*)\
  \| Pstr\_include **of** **include\_declaration**   \
   (\*  **include ME**

 \*)\
  \| Pstr\_attribute **of** **attribute**   \
   (\*  **\[@@@id\]**

 \*)\
  \| Pstr\_extension **of** **extension \* attributes**   \
   (\*  **\[%%id\]**

 \*)

*type value\_constraint* =\
  \| Pvc\_constraint **of {**\
  locally\_abstract\_univars :  **string Asttypes.loc list** ;\
  typ :  **core\_type** ;\
  }\
  \| Pvc\_coercion **of {**\
  ground :  **core\_type option** ;\
  coercion :  **core\_type** ;\
  }   \
   (\* -  **Pvc\_constraint { locally\_abstract\_univars=\[\]; typ}** is a simple type constraint on a value binding:  **let x : typ**

\-More generally, in  **Pvc\_constraint { locally\_abstract\_univars; typ}**

**locally\_abstract\_univars** is the list of locally abstract type variables in  **let x: type a ... . typ**

\- **Pvc\_coercion { ground=None; coercion }** represents  **let x :\> typ**

\- **Pvc\_coercion { ground=Some g; coercion }** represents  **let x : g :\> typ**

 \*)

*type value\_binding* = {\
  pvb\_pat :  **pattern** ;\
  pvb\_expr :  **expression** ;\
  pvb\_constraint :  **value\_constraint option** ;\
  pvb\_attributes :  **attributes** ;\
  pvb\_loc :  **Location.t** ;\
  }

**let pat : type\_constraint = exp**

*type module\_binding* = {\
  pmb\_name :  **string option Asttypes.loc** ;\
  pmb\_expr :  **module\_expr** ;\
  pmb\_attributes :  **attributes** ;\
  pmb\_loc :  **Location.t** ;\
  }

Values of type  **module\_binding** represents  **module X = ME**

### Toplevel

### Toplevel phrases

*type toplevel\_phrase* =\
  \| Ptop\_def **of** **structure**\
  \| Ptop\_dir **of** **toplevel\_directive**   \
   (\*  **#use** ,  **#load** ...\
  \*)

*type toplevel\_directive* = {\
  pdir\_name :  **string Asttypes.loc** ;\
  pdir\_arg :  **directive\_argument option** ;\
  pdir\_loc :  **Location.t** ;\
  }

*type directive\_argument* = {\
  pdira\_desc :  **directive\_argument\_desc** ;\
  pdira\_loc :  **Location.t** ;\
  }

*type directive\_argument\_desc* =\
  \| Pdir\_string **of** **string**\
  \| Pdir\_int **of** **string \* char option**\
  \| Pdir\_ident **of** **Longident.t**\
  \| Pdir\_bool **of** **bool**
