package ppx_repr

  1. Overview
  2. Docs
module Located : sig ... end

Value description

val value_description : name:string Astlib.Location.loc -> type_:Astlib.Ast_500.Parsetree.core_type -> prim:string list -> Astlib.Ast_500.Parsetree.value_description

value_description constructs an Ast.value_description

Example OCaml

Values of type value_description represents:

  • val x: T, when pval_prim is []
  • external x: T = "s1" ... "sn" when pval_prim is ["s1";..."sn"]

Value binding

value_binding constructs an Ast.value_binding

Type extension

type_extension constructs an Ast.type_extension

Example OCaml

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

Type exception

type_exception constructs an Ast.type_exception

Example OCaml

Definition of a new exception (exception E).

Type declaration

type_declaration constructs an Ast.type_declaration

Example OCaml

Here are type declarations and their representation, for various ptype_kind and ptype_manifest values:

  • type t when type_kind is Ptype_abstract, and manifest is None,
  • type t = T0 when type_kind is Ptype_abstract, and manifest is Some T0,
  • type t = C of T | ... when type_kind is Ptype_variant, and manifest is None,
  • type t = T0 = C of T | ... when type_kind is Ptype_variant, and manifest is Some T0,
  • type t = {l: T; ...} when type_kind is Ptype_record, and manifest is None,
  • type t = T0 = {l : T; ...} when type_kind is Ptype_record, and manifest is Some T0,
  • type t = .. when type_kind is Ptype_open, and manifest is None.

Toplevel directive

toplevel_directive constructs an Ast.toplevel_directive

Structure item

pstr_extension constructs an Ast.Pstr_extension

Example OCaml

[%%id]

pstr_attribute constructs an Ast.Pstr_attribute

Example OCaml

[@@@id]

pstr_include constructs an Ast.Pstr_include

Example OCaml

include ME

pstr_class_type constructs an Ast.Pstr_class_type

Example OCaml

class type ct1 = ... and ... and ctn = ...

pstr_class constructs an Ast.Pstr_class

Example OCaml

class c1 = ... and ... and cn = ...

pstr_open constructs an Ast.Pstr_open

Example OCaml

open X

pstr_modtype constructs an Ast.Pstr_modtype

Example OCaml

module type S = MT

pstr_recmodule constructs an Ast.Pstr_recmodule

Example OCaml

module rec X1 = ME1 and ... and Xn = MEn

pstr_module constructs an Ast.Pstr_module

Example OCaml

module X = ME

pstr_exception constructs an Ast.Pstr_exception

Example OCaml

  • exception C of T
  • exception C = M.X

pstr_typext constructs an Ast.Pstr_typext

Example OCaml

type t1 += ...

pstr_type constructs an Ast.Pstr_type

Example OCaml

type t1 = ... and ... and tn = ...

pstr_primitive constructs an Ast.Pstr_primitive

Example OCaml

  • val x: T
  • external x: T = "s1" ... "sn"

pstr_value constructs an Ast.Pstr_value

Example OCaml

Pstr_value(rec, [(P1, E1 ; ... ; (Pn, En))]) represents:

  • let P1 = E1 and ... and Pn = EN when rec is Nonrecursive,
  • let rec P1 = E1 and ... and Pn = EN when rec is Recursive.

pstr_eval constructs an Ast.Pstr_eval

Example OCaml

E

Signature item

psig_extension constructs an Ast.Psig_extension

Example OCaml

[%%id]

psig_attribute constructs an Ast.Psig_attribute

Example OCaml

[@@@id]

psig_class_type constructs an Ast.Psig_class_type

Example OCaml

class type ct1 = ... and ... and ctn = ...

psig_class constructs an Ast.Psig_class

Example OCaml

class c1 : ... and ... and cn : ...

psig_include constructs an Ast.Psig_include

Example OCaml

include MT

psig_open constructs an Ast.Psig_open

Example OCaml

open X

psig_modtypesubst constructs an Ast.Psig_modtypesubst

Example OCaml

module type S := ...

psig_modtype constructs an Ast.Psig_modtype

Example OCaml

module type S = MT and module type S

psig_recmodule constructs an Ast.Psig_recmodule

Example OCaml

module rec X1 : MT1 and ... and Xn : MTn

psig_modsubst constructs an Ast.Psig_modsubst

Example OCaml

module X := M

psig_module constructs an Ast.Psig_module

Example OCaml

module X = M and module X : MT

psig_exception constructs an Ast.Psig_exception

Example OCaml

exception C of T

psig_typext constructs an Ast.Psig_typext

Example OCaml

type t1 += ...

psig_typesubst constructs an Ast.Psig_typesubst

Example OCaml

type t1 := ... and ... and tn := ...

psig_type constructs an Ast.Psig_type

Example OCaml

type t1 = ... and ... and tn = ...

psig_value constructs an Ast.Psig_value

Example OCaml

  • val x: T
  • external x: T = "s1" ... "sn"

Row field

rinherit constructs an Ast.Rinherit

Example OCaml

[ | t ]

rtag constructs an Ast.Rtag

Example OCaml

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)

Position

val position : fname:string -> lnum:int -> bol:int -> cnum:int -> Lexing.position

position constructs an Ast.position

Pattern

ppat_open constructs an Ast.Ppat_open

Example OCaml

Pattern M.(P)

ppat_extension constructs an Ast.Ppat_extension

Example OCaml

Pattern [%id]

ppat_exception constructs an Ast.Ppat_exception

Example OCaml

Pattern exception P

val ppat_unpack : string option Astlib.Location.loc -> Astlib.Ast_500.Parsetree.pattern

ppat_unpack constructs an Ast.Ppat_unpack

Example OCaml

Ppat_unpack(s) represents:

  • (module P) when s is Some "P"
  • (module _) when s is None

Note: (module P : S) is represented as Ppat_constraint(Ppat_unpack(Some "P"), Ptyp_package S)

ppat_lazy constructs an Ast.Ppat_lazy

Example OCaml

Pattern lazy P

ppat_type constructs an Ast.Ppat_type

Example OCaml

Pattern #tconst

ppat_constraint constructs an Ast.Ppat_constraint

Example OCaml

Pattern (P : T)

ppat_or constructs an Ast.Ppat_or

Example OCaml

Pattern P1 | P2

ppat_array constructs an Ast.Ppat_array

Example OCaml

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

ppat_record constructs an Ast.Ppat_record

Example OCaml

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_variant constructs an Ast.Ppat_variant

Example OCaml

Ppat_variant(`A, pat) represents:

  • `A when pat is None,
  • `A P when pat is Some P

ppat_tuple constructs an Ast.Ppat_tuple

Example OCaml

Patterns (P1, ..., Pn).

Invariant: n >= 2

ppat_interval constructs an Ast.Ppat_interval

Example OCaml

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

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

ppat_constant constructs an Ast.Ppat_constant

Example OCaml

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

ppat_alias constructs an Ast.Ppat_alias

Example OCaml

An alias pattern such as P as 'a

ppat_var constructs an Ast.Ppat_var

Example OCaml

A variable pattern such as x

ppat_any constructs an Ast.Ppat_any

Example OCaml

The pattern _.

Object field

oinherit constructs an Ast.Oinherit

Module type declaration

module_type_declaration constructs an Ast.module_type_declaration

Example OCaml

Values of type module_type_declaration represents:

  • S = MT,
  • S for abstract module type declaration, when pmtd_type is None.

Module type

pmty_alias constructs an Ast.Pmty_alias

Example OCaml

(module M)

pmty_extension constructs an Ast.Pmty_extension

Example OCaml

[%id]

pmty_typeof constructs an Ast.Pmty_typeof

Example OCaml

module type of ME

pmty_with constructs an Ast.Pmty_with

Example OCaml

MT with ...

pmty_functor constructs an Ast.Pmty_functor

Example OCaml

functor(X : MT1) -> MT2

pmty_signature constructs an Ast.Pmty_signature

Example OCaml

sig ... end

pmty_ident constructs an Ast.Pmty_ident

Example OCaml

Pmty_ident(S) represents S

Module substitution

module_substitution constructs an Ast.module_substitution

Example OCaml

Values of type module_substitution represents S := M

Module expr

pmod_extension constructs an Ast.Pmod_extension

Example OCaml

[%id]

pmod_unpack constructs an Ast.Pmod_unpack

Example OCaml

(val E)

pmod_constraint constructs an Ast.Pmod_constraint

Example OCaml

(ME : MT)

pmod_apply constructs an Ast.Pmod_apply

Example OCaml

ME1(ME2)

pmod_functor constructs an Ast.Pmod_functor

Example OCaml

functor(X : MT1) -> ME

pmod_structure constructs an Ast.Pmod_structure

Example OCaml

struct ... end

pmod_ident constructs an Ast.Pmod_ident

Example OCaml

X

Module declaration

module_declaration constructs an Ast.module_declaration

Example OCaml

Values of type module_declaration represents S : MT

Module binding

module_binding constructs an Ast.module_binding

Example OCaml

Values of type module_binding represents module X = ME

Location

val location : start:Lexing.position -> end_:Lexing.position -> ghost:bool -> Astlib.Location.t

location constructs an Ast.location

Letop

Label declaration

label_declaration constructs an Ast.label_declaration

Example OCaml

  • { ...; l: T; ... } when pld_mutable is Immutable,
  • { ...; mutable l: T; ... } when pld_mutable is Mutable.

Note: T can be a Ptyp_poly.

Extension constructor

extension_constructor constructs an Ast.extension_constructor

Expression

pexp_unreachable constructs an Ast.Pexp_unreachable

Example OCaml

.

pexp_extension constructs an Ast.Pexp_extension

Example OCaml

[%id]

pexp_letop constructs an Ast.Pexp_letop

Example OCaml

  • let* P = E0 in E1
  • let* P0 = E00 and* P1 = E01 in E1

pexp_open constructs an Ast.Pexp_open

Example OCaml

  • M.(E)
  • let open M in E
  • let open! M in E

pexp_pack constructs an Ast.Pexp_pack

Example OCaml

(module ME).

(module ME : S) is represented as Pexp_constraint(Pexp_pack ME, Ptyp_package S)

pexp_newtype constructs an Ast.Pexp_newtype

Example OCaml

fun (type t) -> E

pexp_object constructs an Ast.Pexp_object

Example OCaml

object ... end

pexp_poly constructs an Ast.Pexp_poly

Example OCaml

Used for method bodies.

Can only be used as the expression under Cfk_concrete for methods (not values).

pexp_lazy constructs an Ast.Pexp_lazy

Example OCaml

lazy E

pexp_assert constructs an Ast.Pexp_assert

Example OCaml

assert E.

Note: assert false is treated in a special way by the type-checker.

pexp_letexception constructs an Ast.Pexp_letexception

Example OCaml

let exception C in E

pexp_letmodule constructs an Ast.Pexp_letmodule

Example OCaml

let module M = ME in E

pexp_override constructs an Ast.Pexp_override

Example OCaml

{< x1 = E1; ...; xn = En >}

pexp_setinstvar constructs an Ast.Pexp_setinstvar

Example OCaml

x <- 2

pexp_new constructs an Ast.Pexp_new

Example OCaml

new M.c

pexp_send constructs an Ast.Pexp_send

Example OCaml

E # m

pexp_coerce constructs an Ast.Pexp_coerce

Example OCaml

Pexp_coerce(E, from, T) represents

  • (E :> T) when from is None,
  • (E : T0 :> T) when from is Some T0.

pexp_constraint constructs an Ast.Pexp_constraint

Example OCaml

(E : T)

pexp_for constructs an Ast.Pexp_for

Example OCaml

Pexp_for(i, E1, E2, direction, E3) represents:

  • for i = E1 to E2 do E3 done when direction is Upto
  • for i = E1 downto E2 do E3 done when direction is Downto

pexp_while constructs an Ast.Pexp_while

Example OCaml

while E1 do E2 done

pexp_sequence constructs an Ast.Pexp_sequence

Example OCaml

E1; E2

pexp_ifthenelse constructs an Ast.Pexp_ifthenelse

Example OCaml

if E1 then E2 else E3

pexp_array constructs an Ast.Pexp_array

Example OCaml

[| E1; ...; En |]

pexp_setfield constructs an Ast.Pexp_setfield

Example OCaml

E1.l <- E2

pexp_field constructs an Ast.Pexp_field

Example OCaml

E.l

pexp_record constructs an Ast.Pexp_record

Example OCaml

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_variant constructs an Ast.Pexp_variant

Example OCaml

Pexp_variant(`A, exp) represents

  • `A when exp is None
  • `A E when exp is Some E

pexp_construct constructs an Ast.Pexp_construct

Example OCaml

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_tuple constructs an Ast.Pexp_tuple

Example OCaml

Expressions (E1, ..., En)

Invariant: n >= 2

pexp_try constructs an Ast.Pexp_try

Example OCaml

try E0 with P1 -> E1 | ... | Pn -> En

pexp_match constructs an Ast.Pexp_match

Example OCaml

match E0 with P1 -> E1 | ... | Pn -> En

pexp_apply constructs an Ast.Pexp_apply

Example OCaml

Pexp_apply(E0, [(l1, E1) ; ... ; (ln, En)]) represents E0 ~l1:E1 ... ~ln:En

li can be Nolabel (non labeled argument), Labelled (labelled arguments) or Optional (optional argument).

Invariant: n > 0

pexp_fun constructs an Ast.Pexp_fun

Example OCaml

Pexp_fun(lbl, exp0, P, E1) represents:

  • fun P -> E1 when lbl is Nolabel and exp0 is None
  • fun ~l:P -> E1 when lbl is Labelled l and exp0 is None
  • fun ?l:P -> E1 when lbl is Optional l and exp0 is None
  • fun ?l:(P = E0) -> E1 when lbl is Optional l and exp0 is Some E0

Notes:

  • If E0 is provided, only Optional is allowed.
  • fun P1 P2 .. Pn -> E1 is represented as nested Pexp_fun.
  • let f P = E is represented using Pexp_fun.

pexp_function constructs an Ast.Pexp_function

Example OCaml

function P1 -> E1 | ... | Pn -> En

pexp_let constructs an Ast.Pexp_let

Example OCaml

Pexp_let(flag, [(P1,E1) ; ... ; (Pn,En)], E) represents:

  • let P1 = E1 and ... and Pn = EN in E when flag is Nonrecursive,
  • let rec P1 = E1 and ... and Pn = EN in E when flag is Recursive.

pexp_constant constructs an Ast.Pexp_constant

Example OCaml

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

pexp_ident constructs an Ast.Pexp_ident

Example OCaml

Identifiers such as x and M.x

Directive argument

pdir_bool constructs an Ast.Pdir_bool

pdir_ident constructs an Ast.Pdir_ident

val pdir_int : string -> char option -> Astlib.Ast_500.Parsetree.directive_argument

pdir_int constructs an Ast.Pdir_int

pdir_string constructs an Ast.Pdir_string

Core type

ptyp_extension constructs an Ast.Ptyp_extension

Example OCaml

[%id].

ptyp_package constructs an Ast.Ptyp_package

Example OCaml

(module S).

ptyp_poly constructs an Ast.Ptyp_poly

Example OCaml

'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 ...
  • Under Cfk_virtual for methods (not values).
  • As the core_type of a Pctf_method node.
  • As the core_type of a Pexp_poly node.
  • As a core_type of a Ptyp_object node.

ptyp_variant constructs an Ast.Ptyp_variant

Example OCaml

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_alias constructs an Ast.Ptyp_alias

Example OCaml

T as 'a.

ptyp_class constructs an Ast.Ptyp_class

Example OCaml

Ptyp_class(tconstr, l) represents:

  • #tconstr when l=[],
  • T #tconstr when l=[T],
  • (T1, ..., Tn) #tconstr when l=[T1 ; ... ; Tn].

ptyp_object constructs an Ast.Ptyp_object

Example OCaml

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_constr constructs an Ast.Ptyp_constr

Example OCaml

Ptyp_constr(lident, l) represents:

  • tconstr when l=[],
  • T tconstr when l=[T],
  • (T1, ..., Tn) tconstr when l=[T1 ; ... ; Tn].

ptyp_tuple constructs an Ast.Ptyp_tuple

Example OCaml

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

Invariant: n >= 2.

ptyp_arrow constructs an Ast.Ptyp_arrow

Example OCaml

Ptyp_arrow(lbl, T1, T2) represents:

val ptyp_var : string -> Astlib.Ast_500.Parsetree.core_type

ptyp_var constructs an Ast.Ptyp_var

Example OCaml

A type variable such as 'a

ptyp_any constructs an Ast.Ptyp_any

Example OCaml

_

Constructor declaration

Class type field

pctf_extension constructs an Ast.Pctf_extension

Example OCaml

[%%id]

pctf_attribute constructs an Ast.Pctf_attribute

Example OCaml

[@@@id]

pctf_constraint constructs an Ast.Pctf_constraint

Example OCaml

constraint T1 = T2

pctf_method constructs an Ast.Pctf_method

Example OCaml

method x: T

Note: T can be a Ptyp_poly.

pctf_inherit constructs an Ast.Pctf_inherit

Example OCaml

inherit CT

Class type

pcty_extension constructs an Ast.Pcty_extension

Example OCaml

%id

pcty_arrow constructs an Ast.Pcty_arrow

Example OCaml

Pcty_arrow(lbl, T, CT) represents:

pcty_signature constructs an Ast.Pcty_signature

Example OCaml

object ... end

pcty_constr constructs an Ast.Pcty_constr

Example OCaml

  • c
  • ['a1, ..., 'an] c

Class structure

class_structure constructs an Ast.class_structure

Example OCaml

Values of type class_structure represents:

  • object(selfpat) ... end
  • object ... end when pcstr_self is Ppat_any

Class signature

class_signature constructs an Ast.class_signature

Example OCaml

Values of type class_signature represents:

  • object('selfpat) ... end
  • object ... end when pcsig_self is Ptyp_any

Class field

pcf_extension constructs an Ast.Pcf_extension

Example OCaml

[%%id]

pcf_attribute constructs an Ast.Pcf_attribute

Example OCaml

[@@@id]

pcf_initializer constructs an Ast.Pcf_initializer

Example OCaml

initializer E

pcf_constraint constructs an Ast.Pcf_constraint

Example OCaml

constraint T1 = T2

pcf_method constructs an Ast.Pcf_method

Example OCaml

  • method x = E (E can be a Pexp_poly)
  • method virtual x: T (T can be a Ptyp_poly)

pcf_val constructs an Ast.Pcf_val

Example OCaml

Pcf_val(x,flag, kind) represents:

  • val x = E when flag is Immutable and kind is Cfk_concrete(Fresh, E)
  • val virtual x: T when flag is Immutable and kind is Cfk_virtual(T)
  • val mutable x = E when flag is Mutable and kind is Cfk_concrete(Fresh, E)
  • val mutable virtual x: T when flag is Mutable and kind is Cfk_virtual(T)

pcf_inherit constructs an Ast.Pcf_inherit

Example OCaml

Pcf_inherit(flag, CE, s) represents:

  • inherit CE when flag is Fresh and s is None,
  • inherit CE as x when flag is Fresh and s is Some x,
  • inherit! CE when flag is Override and s is None,
  • inherit! CE as x when flag is Override and s is Some x

Class expr

pcl_extension constructs an Ast.Pcl_extension

Example OCaml

[%id]

pcl_constraint constructs an Ast.Pcl_constraint

Example OCaml

(CE : CT)

pcl_let constructs an Ast.Pcl_let

Example OCaml

Pcl_let(rec, [(P1, E1); ... ; (Pn, En)], CE) represents:

  • let P1 = E1 and ... and Pn = EN in CE when rec is Nonrecursive,
  • let rec P1 = E1 and ... and Pn = EN in CE when rec is Recursive.

pcl_apply constructs an Ast.Pcl_apply

Example OCaml

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_fun constructs an Ast.Pcl_fun

Example OCaml

Pcl_fun(lbl, exp0, P, CE) represents:

  • fun P -> CE when lbl is Nolabel and exp0 is None,
  • fun ~l:P -> CE when lbl is Labelled l and exp0 is None,
  • fun ?l:P -> CE when lbl is Optional l and exp0 is None,
  • fun ?l:(P = E0) -> CE when lbl is Optional l and exp0 is Some E0.

pcl_structure constructs an Ast.Pcl_structure

Example OCaml

object ... end

pcl_constr constructs an Ast.Pcl_constr

Example OCaml

c and ['a1, ..., 'an] c

Case

case constructs an Ast.case

Example OCaml

Values of type case represents (P -> E) or (P when E0 -> E)

Binding op

binding_op constructs an Ast.binding_op

Attribute

attribute constructs an Ast.attribute

Example OCaml

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

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

'a open infos

open_infos constructs an Ast.'aopen_infos

Example OCaml

Values of type 'a open_infos represents:

  • open! X when popen_override is Override (silences the "used identifier shadowing" warning)
  • open X when popen_override is Fresh

'a include infos

val include_infos : 'a -> 'a Astlib.Ast_500.Parsetree.include_infos

include_infos constructs an Ast.'ainclude_infos

'a class infos

class_infos constructs an Ast.'aclass_infos

Example OCaml

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.

val estring : string -> Astlib.Ast_500.Parsetree.expression
val enativeint : nativeint -> Astlib.Ast_500.Parsetree.expression
val pstring : string -> Astlib.Ast_500.Parsetree.pattern
val pfloat : string -> Astlib.Ast_500.Parsetree.pattern
val pint32 : int32 -> Astlib.Ast_500.Parsetree.pattern
val pint64 : int64 -> Astlib.Ast_500.Parsetree.pattern
val pnativeint : nativeint -> Astlib.Ast_500.Parsetree.pattern

evar id produces a Pexp_ident _ expression, it parses its input so you can pass any dot-separated identifier, for instance: evar ~loc "Foo.bar".

elist_tail ~loc [expr1; expr2; expr3] expr_tail produces the expression expr1::expr2::expr3::expr_tail.

elist ~loc [expr1; expr2; expr3] produces the list litteral expression [expr1; expr2; expr3].

plist_tail ~loc [pat1; pat2; pat3] pat_tail produces the pattern pat1::pat2::pat3::pat_tail.

plist ~loc [pat1; pat2; pat3] produces the list pattern [pat1; pat2; pat3].

pstr_value_list ~loc rf vbs = pstr_value ~loc rf vbs if vbs <> [], [] otherwise.

  • deprecated [since 2016-10] use Nonrecursive on the P(str|sig)_type instead
val unapplied_type_constr_conv : Ppxlib.Longident.t Ppxlib.Loc.t -> f:(string -> string) -> Astlib.Ast_500.Parsetree.expression

unapplied_type_constr_conv is the standard way to map identifiers to conversion fonctions, for preprocessor that creates values that follow the structure of types. More precisely, path_conv path (sprintf "sexp_of_%s") is:

  • sexp_of_t if path is "t"
  • A.B.sexp_of_foo if path is "A.B.foo"
  • A.B.sexp_of_f__foo (module A1) (module A2) if path is "A.B.F(A1)(A2).foo" type_constr_conv also applies it to a list of expression, which both prevents the compiler from allocating useless closures, and almost always what is needed, since type constructors are always applied.

Tries to simplify fun v1 v2 .. -> f v1 v2 .. into f. Only works when f is a path, not an arbitrary expression as that would change the meaning of the code. This can be used either for cleaning up the generated code, or to reduce allocation if f is a local variable (the compiler won't optimize the allocation of the closure).

Eta-reduction can change the types/behavior in some corner cases that are unlikely to show up in generated code:

  • if f has optional arguments, eta-expanding f can drop them
  • because labels commute, it can change the type of an expression: $ let f ~x y = x + y let f2 = fun x -> add x;; val f : x:int -> int -> int = <fun> val f2 : int -> x:int -> int = <fun> In fact, if f does side effects before receiving all its arguments, and if the eta-expansion is partially applied, eta-reducing could change behavior.

eta_reduce_if_possible_and_nonrec is meant for the case where the resulting expression is going to be bound in a potentially recursive let-binding, where we have to keep the eta-expansion when rec_flag is Recursive to avoid a compile error.

module Latest : sig ... end

This module contains updated versions of node constructors that were kept stable when the node changed. For every function in this module, there's an equally-named function outside this module. The function outside this module will stay stable, whereas the function inside this module will adapt potential upcoming new compiler features. Only use a function in this module, if the equally-named one outside this module is missing a feature you need.

OCaml

Innovation. Community. Security.