package ppxlib_jane

  1. Overview
  2. Docs

Module Jane_syntax.N_ary_functionsSource

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

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

Sourcetype function_param_desc =
  1. | Pparam_val of Ppxlib_jane__.Shadow_compiler_distribution.Asttypes.arg_label * Ppxlib_jane__.Shadow_compiler_distribution.Parsetree.expression option * Ppxlib_jane__.Shadow_compiler_distribution.Parsetree.pattern
    (*

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

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

    *)
  2. | Pparam_newtype of string Ppxlib_jane__.Shadow_compiler_distribution.Asttypes.loc * Ppxlib_jane__.Jane_asttypes.const_jkind Location.loc option
    (*

    Pparam_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.

    *)
Sourcetype function_param = {
  1. pparam_desc : function_param_desc;
  2. pparam_loc : Location.t;
}
Sourcetype type_constraint =
  1. | Pconstraint of Ppxlib_jane__.Shadow_compiler_distribution.Parsetree.core_type
  2. | Pcoerce of Ppxlib_jane__.Shadow_compiler_distribution.Parsetree.core_type option * Ppxlib_jane__.Shadow_compiler_distribution.Parsetree.core_type
Sourcetype 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 = ....

Sourcetype 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.

Sourceval expr_of : loc:Location.t -> expression -> Ppxlib_jane__.Shadow_compiler_distribution.Parsetree.expression