package ppxlib_jane

  1. Overview
  2. Docs

These types use the P prefix to match how they are represented in the upstream compiler

type function_body =
  1. | Pfunction_body of Ppxlib_ast.Parsetree.expression
  2. | Pfunction_cases of Ppxlib_ast.Parsetree.case list * Location.t * Ppxlib_ast.Parsetree.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 expression.

type function_param_desc =
  1. | Pparam_val of Ppxlib_ast.Asttypes.arg_label * Ppxlib_ast.Parsetree.expression option * Ppxlib_ast.Parsetree.pattern
    (*

    Pparam_val (lbl, exp0, P) represents the parameter:

    Note: If E0 is provided, only Optional is allowed.

    *)
type function_param = {
  1. pparam_desc : function_param_desc;
  2. pparam_loc : Location.t;
}
type type_constraint =
  1. | Pconstraint of Ppxlib_ast.Parsetree.core_type
  2. | Pcoerce of Ppxlib_ast.Parsetree.core_type option * Ppxlib_ast.Parsetree.core_type
type function_constraint = {
  1. mode_annotations : Mode_expr.t;
  2. 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 = ....

type expression = function_param list * function_constraint option * function_body

([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 : 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.

OCaml

Innovation. Community. Security.