package catala

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

Functions handling the code item structures of shared_ast, in particular the scopes

Traversal functions

val map_exprs_in_lets : ?typ: (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> f:('expr1 -> 'expr2 Shared_ast__.Definitions.boxed) -> varf:('expr1 Var.t -> 'expr2 Var.t) -> ('expr1, 'expr1 Shared_ast__.Definitions.scope_let, 'expr1) Shared_ast__.Definitions.bound_list -> ('expr2, 'expr2 Shared_ast__.Definitions.scope_let, 'expr2) Shared_ast__.Definitions.bound_list Bindlib.box

Usage map_exprs_in_lets ~f:(fun e -> ...) ~varf:(fun var -> ...) scope_body_expr, where e is the right-hand-side of a scope let or the result of the scope body, and var represents the left-hand-side variable of a scope let. ~varf is usually the identity function or Var.translate when the map sends the expression to a new flavor of the shared AST. If ~reset_types is activated, then the resulting types in the scope let left-hand-sides will be reset to TAny.

val map_exprs : ?typ: (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> f:('expr1 -> 'expr2 Shared_ast__.Definitions.boxed) -> varf:('expr1 Var.t -> 'expr2 Var.t) -> ('expr1, 'expr1 Shared_ast__.Definitions.code_item, unit) Shared_ast__.Definitions.bound_list -> ('expr2, 'expr2 Shared_ast__.Definitions.code_item, unit) Shared_ast__.Definitions.bound_list Bindlib.box

This is the main map visitor for all the expressions inside all the scopes of the program.

val fold_exprs : f: ('acc -> 'expr -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> 'acc) -> init:'acc -> ('expr, 'expr Shared_ast__.Definitions.code_item, unit) Shared_ast__.Definitions.bound_list -> 'acc

Conversions

val to_expr : Shared_ast__.Definitions.decl_ctx -> (('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 Shared_ast__.Definitions.scope_body -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Usage: to_expr ctx body scope_position where scope_position corresponds to the line of the scope declaration for instance.

val unfold : Shared_ast__.Definitions.decl_ctx -> (((_, _, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed as 'e, ((_, _, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed as 'e Shared_ast__.Definitions.code_item, unit) Shared_ast__.Definitions.bound_list -> Shared_ast__.Definitions.ScopeName.t -> 'e Shared_ast__.Definitions.boxed
val typ : _ Shared_ast__.Definitions.scope_body -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos

builds the arrow type for the specified scope

val input_type : Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Runtime_ocaml.Runtime.io_input Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos

Returns the correct input type for scope input variables: this is typ for non-reentrant variables, but for reentrant variables, it is nested in a TDefault, which only applies to the return type on functions. Note that this doesn't take thunking into account (thunking is added during the scopelang->dcalc translation)

Analysis and tests

val free_vars_body_expr : ('e, 'e Shared_ast__.Definitions.scope_let, 'e) Shared_ast__.Definitions.bound_list -> 'e Var.Set.t
val free_vars_item : 'e Shared_ast__.Definitions.code_item -> 'e Var.Set.t
val free_vars : ('e, 'e Shared_ast__.Definitions.code_item, unit) Shared_ast__.Definitions.bound_list -> 'e Var.Set.t