package catala

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Functions handling the expressions of shared_ast

Boxed constructors

val box : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Box the expression from the outside

val unbox : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

For closed expressions, similar to Bindlib.unbox

val unbox_closed : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Similar to unbox, but with an added assertion check on the expression being closed

val rebox : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Rebuild the whole term, re-binding all variables and exposing free variables

val evar : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.t -> 'm Shared_ast__.Definitions.mark -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eexternal : name:Shared_ast__.Definitions.external_ref Catala_utils.Mark.pos -> 'm Shared_ast__.Definitions.mark -> ((< explicitScopes : Shared_ast__.Definitions.no.. >, < explicitScopes : Shared_ast__.Definitions.no.. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val bind : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.t array -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) Bindlib.mbinder Bindlib.box
val subst : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) Bindlib.mbinder -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val etuple : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val etupleaccess : e: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> index:int -> size:int -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val earray : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val elit : Shared_ast__.Definitions.lit -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eabs : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) Bindlib.mbinder Bindlib.box -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos list -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eapp : f: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> args: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> tys:Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos list -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eassert : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> ((< assertions : Shared_ast__.Definitions.yes.. > as 'a, < assertions : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val efatalerror : Runtime_ocaml.Runtime.error -> 'm Shared_ast__.Definitions.mark -> ((< .. >, < .. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eappop : op:'a Shared_ast__.Definitions.Op.t Catala_utils.Mark.pos -> args: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> tys:Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos list -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val edefault : excepts: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> just: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> cons: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> ((< defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, < defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val epuredefault : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> ((< defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, < defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eifthenelse : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eempty : 'm Shared_ast__.Definitions.mark -> ((< defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, < defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eerroronempty : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> ((< defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, < defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val ecatchempty : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> ((< exceptions : Shared_ast__.Definitions.yes.. > as 'a, < exceptions : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val eraiseempty : 'm Shared_ast__.Definitions.mark -> ((< exceptions : Shared_ast__.Definitions.yes.. >, < exceptions : Shared_ast__.Definitions.yes.. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val elocation : 'a Shared_ast__.Definitions.glocation -> 'm Shared_ast__.Definitions.mark -> ((< .. > as 'a, < .. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val estruct : name:Shared_ast__.Definitions.StructName.t -> fields: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.StructField.Map.t -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val edstructamend : name_opt:Shared_ast__.Definitions.StructName.t option -> e: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> fields: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Catala_utils.String.Map.t -> 'm Shared_ast__.Definitions.mark -> ((< syntacticNames : Shared_ast__.Definitions.yes.. > as 'a, < syntacticNames : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val edstructaccess : name_opt:Shared_ast__.Definitions.StructName.t option -> field:Catala_utils.String.t -> e: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> ((< syntacticNames : Shared_ast__.Definitions.yes.. > as 'a, < syntacticNames : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val estructaccess : name:Shared_ast__.Definitions.StructName.t -> field:Shared_ast__.Definitions.StructField.t -> e: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val einj : name:Shared_ast__.Definitions.EnumName.t -> cons:Shared_ast__.Definitions.EnumConstructor.t -> e: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val ematch : name:Shared_ast__.Definitions.EnumName.t -> e: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> cases: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.EnumConstructor.Map.t -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val escopecall : scope:Shared_ast__.Definitions.ScopeName.t -> args: (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.ScopeVar.Map.t -> 'm Shared_ast__.Definitions.mark -> ((< explicitScopes : Shared_ast__.Definitions.yes.. > as 'a, < explicitScopes : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val ecustom : Stdlib.Obj.t -> Type.t list -> Type.t -> 'm Shared_ast__.Definitions.mark -> ((< custom : Shared_ast__.Definitions.yes.. >, < custom : Shared_ast__.Definitions.yes.. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val fun_id : ?var_name:string -> 'm Shared_ast__.Definitions.mark -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

The type of the mark, if typed, is assumed to correspond to the argument type, not the function type

Manipulation of marks

val no_mark : 'm Shared_ast__.Definitions.mark -> 'm Shared_ast__.Definitions.mark

Returns an empty mark, using the argument as type witness. Note that the custom part is kept on Custom marks

val mark_pos : 'm Shared_ast__.Definitions.mark -> Catala_utils.Pos.t
val with_pos : Catala_utils.Pos.t -> 'm Shared_ast__.Definitions.mark -> 'm Shared_ast__.Definitions.mark
val with_ty : 'm Shared_ast__.Definitions.mark -> ?pos:Catala_utils.Pos.t -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> 'm Shared_ast__.Definitions.mark

Adds the given type information only on typed marks

val map_ty : (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> 'm Shared_ast__.Definitions.mark -> 'm Shared_ast__.Definitions.mark

Identity on untyped marks

val map_mark : (Catala_utils.Pos.t -> Catala_utils.Pos.t) -> (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> 'm Shared_ast__.Definitions.mark -> 'm Shared_ast__.Definitions.mark
val map_mark2 : (Catala_utils.Pos.t -> Catala_utils.Pos.t -> Catala_utils.Pos.t) -> (Shared_ast__.Definitions.typed -> Shared_ast__.Definitions.typed -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> 'm Shared_ast__.Definitions.mark -> 'm Shared_ast__.Definitions.mark -> 'm Shared_ast__.Definitions.mark
  • raises Invalid_arg

    on custom marks

val fold_marks : (Catala_utils.Pos.t list -> Catala_utils.Pos.t) -> (Shared_ast__.Definitions.typed list -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> 'm Shared_ast__.Definitions.mark list -> 'm Shared_ast__.Definitions.mark
  • raises Invalid_arg

    on custom marks

val maybe_ty : ?typ:Shared_ast__.Definitions.naked_typ -> 'm Shared_ast__.Definitions.mark -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos

Returns the corresponding type on a typed expr, or typ (defaulting to TAny) at the current position on an untyped one

val untyped : Shared_ast__.Definitions.untyped Shared_ast__.Definitions.mark

Type witness for untyped marks

val typed : Shared_ast__.Definitions.typed Shared_ast__.Definitions.mark

Type witness for untyped marks

Predefined types

val option_enum : Shared_ast__.Definitions.EnumName.t
val none_constr : Shared_ast__.Definitions.EnumConstructor.t
val some_constr : Shared_ast__.Definitions.EnumConstructor.t
val option_enum_config : Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos Shared_ast__.Definitions.EnumConstructor.Map.t

Manipulation of marked expressions

val pos : ('a, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> Catala_utils.Pos.t
val ty : ('e, Shared_ast__.Definitions.typed Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos
val set_ty : Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> ('a, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> ('a, Shared_ast__.Definitions.typed Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val untype : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, Shared_ast__.Definitions.untyped) Shared_ast__.Definitions.base_gexpr Bindlib.box, Shared_ast__.Definitions.untyped Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Traversal functions

val map : ?typ: (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> ?op: ('a Shared_ast__.Definitions.Op.t Catala_utils.Mark.pos -> 'b Shared_ast__.Definitions.Op.t Catala_utils.Mark.pos) -> f: ((('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('b, 'b, 'm2) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) -> (('a, 'b, 'm1) Shared_ast__.Definitions.base_gexpr, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('b, 'b, 'm2) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Shallow mapping on expressions (non recursive): applies the given function to all sub-terms of the given expression, and rebuilds the node.

This function makes it very concise to transform only certain nodes of the AST. For instance, if you want to remove all errors on empty, you can write

let remove_error_empty e =
  let rec f e =
    match Mark.remove e with
    | EErrorOnEmpty e1 -> Expr.map ~f e1
    | _ -> Expr.map ~f e
  in
  f e

This can even be used to translate between different kinds of ASTs: see Lcalc.Compile_without_exceptions for an example. The structure is like this:

let rec translate = function
  | SpecificCase e -> TargetCase (translate e)
  | (All | Other | Common | Cases) as e -> Expr.map ~f:translate e

The e parameter passed to map here needs to have only the common cases in its shallow type, but can still contain any node from the starting AST deeper inside: this is where the second type parameter to base_gexpr becomes useful.

The typ argument, if specified, will apply a transformation both on type annotations, if present, and on types appearing within the AST nodes.

The op argument must be specified for the EAppOp case to be handled.

val map_top_down : f: ((('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) -> (('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm2) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Recursively applies f to the nodes of the expression tree. The type returned by f is hybrid since the mark at top-level has been rewritten, but not yet the marks in the subtrees.

val map_marks : f:('m1 Shared_ast__.Definitions.mark -> 'm2 Shared_ast__.Definitions.mark) -> (('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm2) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val shallow_fold : ((('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'acc -> 'acc) -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'acc -> 'acc

Applies a function on all sub-terms of the given expression. Does not recurse. It opens binders unless you avoid sending binders to the function like the example below. Useful as helper for recursive calls within traversal functions. This can be used to compute free variables with e.g.:

let rec free_vars = function
  | EVar v, _ -> Var.Set.singleton v
  | EAbs { binder; _ }, _ ->
    let vs, body = Bindlib.unmbind binder in
    Array.fold_right Var.Set.remove vs (free_vars body)
  | e ->
    shallow_fold (fun e -> Var.Set.union (free_vars e)) e Var.Set.empty
val map_gather : acc:'acc -> join:('acc -> 'acc -> 'acc) -> f: ((('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'acc * (('a, 'a, 'm2) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) -> (('a, 'a, 'm1) Shared_ast__.Definitions.base_gexpr, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> 'acc * (('a, 'a, 'm2) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Shallow mapping similar to map, but additionally allows to gather an accumulator bottom-up. acc is the accumulator value returned on terminal nodes, and join is used to merge accumulators from the different sub-terms of an expression. acc is assumed to be a neutral element for join. Typically used with a set of variables used in the rewrite:

let rec rewrite e =
  match Mark.remove e with
  | Specific_case -> Var.Set.singleton x, some_rewrite_fun e
  | _ ->
    Expr.map_gather ~acc:Var.Set.empty ~join:Var.Set.union ~f:rewrite e

See Lcalc.closure_conversion for a real-world example.

Expression building helpers

val make_var : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.t -> 'm Shared_ast__.Definitions.mark -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val make_abs : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.vars -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos list -> Catala_utils.Pos.t -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val make_app : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos list -> Catala_utils.Pos.t -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val make_puredefault : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> ((< defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, < defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val make_erroronempty : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> ((< defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, < defaultTerms : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val empty_thunked_term : 'm Shared_ast__.Definitions.mark -> ((< defaultTerms : Shared_ast__.Definitions.yes.. >, < defaultTerms : Shared_ast__.Definitions.yes.. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val thunk_term : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'b) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'b Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'b) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'b Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val unthunk_term_nobox : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Remove thunking around an expression (this assumes it's the right form, raises Invalid_argument otherwise)

val make_let_in : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.t -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> Catala_utils.Pos.t -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val make_multiple_let_in : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.vars -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos list -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> Catala_utils.Pos.t -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed
val make_tuple : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed list -> 'm Shared_ast__.Definitions.mark -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Builds a tuple; the mark argument is only used as witness and for position when building 0-uples

val make_tupleaccess : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> int -> int -> Catala_utils.Pos.t -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Transformations

val skip_wrappers : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Removes surface logging calls and EErrorOnEmpty nodes. Shallow function

val remove_logging_calls : ((< polymorphic : Shared_ast__.Definitions.yes.. > as 'a, < polymorphic : Shared_ast__.Definitions.yes.. > as 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Removes all calls to Log unary operators in the AST, replacing them by their argument.

val rename_vars : ?exclude:string list -> ?reset_context_for_closed_terms:bool -> ?skip_constant_binders:bool -> ?constant_binder_name:string option -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Disambiguates all variable names in e. exclude will blacklist the given names (useful for keywords or built-in names) ; the other flags behave as defined in the bindlib documentation for module type Rename

val format : Stdlib.Format.formatter -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> unit

Simple printing without debug, use Print.expr () instead to follow the command-line debug setting

Analysis and tests

val equal_lit : Shared_ast__.Definitions.lit -> Shared_ast__.Definitions.lit -> bool
val compare_lit : Shared_ast__.Definitions.lit -> Shared_ast__.Definitions.lit -> int
val equal_location : 'a Shared_ast__.Definitions.glocation Catala_utils.Mark.pos -> 'a Shared_ast__.Definitions.glocation Catala_utils.Mark.pos -> bool
val compare_location : 'a Shared_ast__.Definitions.glocation Catala_utils.Mark.pos -> 'a Shared_ast__.Definitions.glocation Catala_utils.Mark.pos -> int
val equal : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> bool

Determines if two expressions are equal, omitting their position information

val compare : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> int

Standard comparison function, suitable for e.g. Set.Make. Ignores position information

val is_value : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> bool
val free_vars : (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Var.Set.t
val size : (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> int

Used by the optimizer to know when to stop

module Box : sig ... end
OCaml

Innovation. Community. Security.