Module type Ast_builder_intf.Additional_helpers
val eint : (Ppxlib__.Import.int -> Ppxlib__.Import.expression) with_loc
val echar : (Ppxlib__.Import.char -> Ppxlib__.Import.expression) with_loc
val estring : (Ppxlib__.Import.string -> Ppxlib__.Import.expression) with_loc
val efloat : (Ppxlib__.Import.string -> Ppxlib__.Import.expression) with_loc
val eint32 : (Ppxlib__.Import.int32 -> Ppxlib__.Import.expression) with_loc
val eint64 : (Ppxlib__.Import.int64 -> Ppxlib__.Import.expression) with_loc
val enativeint : (Ppxlib__.Import.nativeint -> Ppxlib__.Import.expression) with_loc
val ebool : (Ppxlib__.Import.bool -> Ppxlib__.Import.expression) with_loc
val pint : (Ppxlib__.Import.int -> Ppxlib__.Import.pattern) with_loc
val pchar : (Ppxlib__.Import.char -> Ppxlib__.Import.pattern) with_loc
val pstring : (Ppxlib__.Import.string -> Ppxlib__.Import.pattern) with_loc
val pfloat : (Ppxlib__.Import.string -> Ppxlib__.Import.pattern) with_loc
val pint32 : (Ppxlib__.Import.int32 -> Ppxlib__.Import.pattern) with_loc
val pint64 : (Ppxlib__.Import.int64 -> Ppxlib__.Import.pattern) with_loc
val pnativeint : (Ppxlib__.Import.nativeint -> Ppxlib__.Import.pattern) with_loc
val pbool : (Ppxlib__.Import.bool -> Ppxlib__.Import.pattern) with_loc
val eunit : Ppxlib__.Import.expression with_loc
val punit : Ppxlib__.Import.pattern with_loc
val evar : (Ppxlib__.Import.string -> Ppxlib__.Import.expression) with_loc
evar id
produces aPexp_ident _
expression, it parses its input so you can pass any dot-separated identifier, for instance:evar ~loc "Foo.bar"
.
val pvar : (Ppxlib__.Import.string -> Ppxlib__.Import.pattern) with_loc
val eapply : (Ppxlib__.Import.expression -> Ppxlib__.Import.expression Ppxlib__.Import.list -> Ppxlib__.Import.expression) with_loc
Same as pexp_apply but without labels
val eabstract : (Ppxlib__.Import.pattern Ppxlib__.Import.list -> Ppxlib__.Import.expression -> Ppxlib__.Import.expression) with_loc
val esequence : (Ppxlib__.Import.expression Ppxlib__.Import.list -> Ppxlib__.Import.expression) with_loc
val ppat_tuple_opt : (Ppxlib__.Import.pattern Ppxlib__.Import.list -> Ppxlib__.Import.pattern Ppxlib__.Import.option) with_loc
val pexp_tuple_opt : (Ppxlib__.Import.expression Ppxlib__.Import.list -> Ppxlib__.Import.expression Ppxlib__.Import.option) with_loc
val pconstruct : Ppxlib__.Import.constructor_declaration -> Ppxlib__.Import.pattern Ppxlib__.Import.option -> Ppxlib__.Import.pattern
val econstruct : Ppxlib__.Import.constructor_declaration -> Ppxlib__.Import.expression Ppxlib__.Import.option -> Ppxlib__.Import.expression
val elist : (Ppxlib__.Import.expression Ppxlib__.Import.list -> Ppxlib__.Import.expression) with_loc
val plist : (Ppxlib__.Import.pattern Ppxlib__.Import.list -> Ppxlib__.Import.pattern) with_loc
val pstr_value_list : loc:Ppxlib.Location.t -> Ppxlib__.Import.Asttypes.rec_flag -> Ppxlib__.Import.value_binding Ppxlib__.Import.list -> Ppxlib__.Import.structure_item Ppxlib__.Import.list
pstr_value_list ~loc rf vbs
=pstr_value ~loc rf vbs
ifvbs <> []
,[]
otherwise.
val nonrec_type_declaration : (name:Ppxlib__.Import.string Ppxlib.Loc.t -> params:(Ppxlib__.Import.core_type * Ppxlib__.Import.Asttypes.variance) Ppxlib__.Import.list -> cstrs:(Ppxlib__.Import.core_type * Ppxlib__.Import.core_type * Ppxlib.Location.t) Ppxlib__.Import.list -> kind:Ppxlib__.Import.type_kind -> private_:Ppxlib__.Import.Asttypes.private_flag -> manifest:Ppxlib__.Import.core_type Ppxlib__.Import.option -> Ppxlib__.Import.type_declaration) with_loc
val unapplied_type_constr_conv : (Ppxlib.Longident.t Ppxlib.Loc.t -> f:(Ppxlib__.Import.string -> Ppxlib__.Import.string) -> Ppxlib__.Import.expression) with_loc
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.
val type_constr_conv : (Ppxlib.Longident.t Ppxlib.Loc.t -> f:(Ppxlib__.Import.string -> Ppxlib__.Import.string) -> Ppxlib__.Import.expression Ppxlib__.Import.list -> Ppxlib__.Import.expression) with_loc
val eta_reduce : Ppxlib__.Import.expression -> Ppxlib__.Import.expression Ppxlib__.Import.option
Tries to simplify
fun v1 v2 .. -> f v1 v2 ..
intof
. Only works whenf
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 iff
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-expandingf
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 whenrec_flag
isRecursive
to avoid a compile error.- if
val eta_reduce_if_possible : Ppxlib__.Import.expression -> Ppxlib__.Import.expression
val eta_reduce_if_possible_and_nonrec : Ppxlib__.Import.expression -> rec_flag:Ppxlib__.Import.rec_flag -> Ppxlib__.Import.expression