package catala

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module D = Ast

Alternative representation of the Dcalc Ast. It is currently used in the transformation without exceptions. We make heavy use of bindlib, binding each scope-let-variable and each scope explicitly.

type scope_lets =
  1. | Result of D.expr Utils.Pos.marked
  2. | ScopeLet of {
    1. scope_let_kind : D.scope_let_kind;
    2. scope_let_typ : D.typ Utils.Pos.marked;
    3. scope_let_expr : D.expr Utils.Pos.marked;
    4. scope_let_next : (D.expr, scope_lets) Bindlib.binder;
    5. scope_let_pos : Utils.Pos.t;
    }

In Ast, Ast.scope_lets is defined as a list of kind, var, and boxed expression. This representation binds using bindlib the tail of the list with the variable defined in the let.

type scope_body = {
  1. scope_body_input_struct : D.StructName.t;
  2. scope_body_output_struct : D.StructName.t;
  3. scope_body_result : (D.expr, scope_lets) Bindlib.binder;
}

As a consequence, the scope_body contains only a result and input/output signature, as the other elements are stored inside the scope_let. The binder present is the argument of type scope_body_input_struct.

type scopes =
  1. | Nil
  2. | ScopeDef of {
    1. scope_name : D.ScopeName.t;
    2. scope_body : scope_body;
    3. scope_next : (D.expr, scopes) Bindlib.binder;
    }

Finally, we do the same transformation for the whole program for the kinded lets. This permit us to use bindlib variables for scopes names.

val free_vars_list_scope_lets : scope_lets -> D.Var.t list

List of variables not binded inside a scope_lets

val free_vars_list_scope_body : scope_body -> D.Var.t list

List of variables not binded inside a scope_body.

val free_vars_list_scopes : scopes -> D.Var.t list

List of variables not binded inside scopes

val bind_scopes : (D.ScopeName.t * D.expr Bindlib.var * D.scope_body) list -> scopes Bindlib.box

Transform a list of scopes into our representation of scopes. It requires that scopes are topologically-well-ordered, and ensure there is no free variables in the returned scopes

OCaml

Innovation. Community. Security.