Jane_syntax.N_ary_functionsSourceThese types use the P prefix to match how they are represented in the upstream compiler
type function_body = | Pfunction_body of Ppxlib_ast.Parsetree.expression| Pfunction_cases of Ppxlib_ast.Parsetree.case list
* Location.t
* Ppxlib_ast.Parsetree.attributesIn 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 expression.
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 type_constraint = | Pconstraint of Ppxlib_ast.Parsetree.core_type| Pcoerce of Ppxlib_ast.Parsetree.core_type option
* Ppxlib_ast.Parsetree.core_typetype function_constraint = {mode_annotations : Mode_expr.t;type_constraint : 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 = ....
([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.