Jane_syntax.N_ary_functionsThese types use the P prefix to match how they are represented in the upstream compiler
type function_param_desc = | Pparam_val of Ppxlib_ast.Asttypes.arg_label
* Ppxlib_ast.Parsetree.expression option
* Ppxlib_ast.Parsetree.patternPparam_val (lbl, exp0, P) represents the parameter:
P when lbl is Nolabel and exp0 is None~l:P when lbl is Labelled l and exp0 is None?l:P when lbl is Optional l and exp0 is None?l:(P = E0) when lbl is Optional l and exp0 is Some E0Note: If E0 is provided, only Optional is allowed.
| Pparam_newtype of string Ppxlib_ast.Asttypes.loc
* Ppxlib_jane__.Jane_asttypes.const_jkind Location.loc optionPparam_newtype (x, jkind) represents the parameter (type x). x carries the location of the identifier, whereas pparam_loc is the location of the (type x) as a whole.
jkind is the same as Lexp_newtype's jkind.
Multiple parameters (type a b c) are represented as multiple Pparam_newtype nodes, let's say:
[ { pparam_desc = Pparam_newtype (a, _); pparam_loc = loc };
{ pparam_desc = Pparam_newtype (b, _); pparam_loc = loc };
{ pparam_desc = Pparam_newtype (c, _); pparam_loc = loc };
]Here, loc gives the location of (type a b c), but is marked as a ghost location. The locations on a, b, c, correspond to the variables a, b, and c in the source code.
type function_constraint = {mode_annotations : Mode_expr.t;type_constraint : Ppxlib_ast.Parsetree.type_constraint;}The mode annotation placed on a function let-binding when the function has a type constraint on the body, e.g. let local_ f x : int -> int = ....
type expression =
function_param list
* function_constraint option
* Ppxlib_ast.Parsetree.function_body([P1; ...; Pn], C, body) represents any construct involving fun or function, including:
fun P1 ... Pn -> E when body = Pfunction_body Efun 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 : t1 :> t2 -> ... when C = Some (Pcoerce (Some t1, t2)).
A function must have parameters. Pexp_function (params, _, body) must have non-empty params or a Pfunction_cases _ body.
val expr_of : loc:Location.t -> expression -> Ppxlib_ast.Parsetree.expression