Catala_runtimeThe OCaml runtime.
type date = Dates_calc.datetype duration = Dates_calc.periodtype io_input = | NoInputFor an internal variable defined only in the scope, and does not appear in the input.
*)| OnlyInputFor variables that should not be redefined in the scope, because they appear in the input.
*)| ReentrantFor variables defined in the scope that can also be redefined by the caller as they appear in the input.
*)This type characterizes the three levels of visibility for a given scope variable with regards to the scope's input and possible redefinitions inside the scope.
type error = | AssertionFailedAn assertion in the program doesn't hold
*)| NoValueNo computation with valid conditions found
*)| ConflictTwo different valid computations at that point
*)| DivisionByZeroThe denominator happened to be 0 here
*)| ListEmptyElement access on an empty list
*)| NotSameLengthTraversing multiple lists of different lengths
*)| UncomparableValuesEquality check or comparison on functions
*)| DateError of stringErrors related to date and duration computations
*)| ImpossibleThe "impossible" keyword was reached
*)val error_to_string : error -> stringReturns the capitalized tag of the error as a string
val error_message : error -> stringReturns a short explanation message about the error
exception Error of error * code_location list * string optionmodule Value : sig ... endval equal : 'a Value.ty -> code_location -> 'a -> 'a -> boolPolymorphic, structural equality using runtime type information
val compare : 'a Value.ty -> code_location -> 'a -> 'a -> intPolymorphic, structural comparison using runtime type information
module type CatalaType = sig ... endmodule Optional : sig ... endmodule type ExternalTypeSpec = sig ... endThis interface must be supplied to extend the Catala runtime with abstract types
module ExternalType (Spec : ExternalTypeSpec) : CatalaType with type t = Spec.tThe trace construction mechanism is a stateful process (i.e., non-reentrant) that collect traces emitted by the generated trace constructors defined below.
The built trace is organized as a tree where each node represent a trace element (e.g., a variable definition, a branching, etc.) which may have sub-traces. For instance, a function that defines local variable definitions will be represented as a FunCall node with a sub_trace containing these LocalVarDef sub-nodes.
Conceptually, whenever we reach a trace event, we open a scope, evaluate the sub-expression potentially yielding new traces that will be its sub-nodes, close the scope and finalize this trace node with the computed sub-expression value.
Whenever a runtime error is triggered, we insert an Error node as a sub-trace of the currently opened scope and re-raise this error. This is automatically performed by the with_trace wrapper.
The global trace state can be retrieved using the retrieve_trace accessor and cleared using reset_trace.
type trace_kind = | ScopeCall of trace_ident_declScope call with the scope declaration information
*)| ScopeVarDef of {var : trace_ident_decl;io : io_log;}Scope variable definition with its declaration information and its i/o kind
*)| LocalVarDef of stringLet-binding of a local variable with its name
*)| LocalTupDef of string listLet-binding of a local tuple with the name of each binded variable
*)| FunCall of trace_ident_declFunction call with its declaration information
*)| BranchingConditionBranching condition for an if-then-else or a pattern matching
*)| IfBranchingBranch taken of the consequence or alternative of an if-then-else
*)| MatchBranching of {}Pattern taken of a pattern-matching
*)| AssertionBeginning of an assertion
*)| Exception of {label : (string * code_location) option;Exception label and its position in case of named exception
*)cons_pos : code_location;Position of the consequence that would be evaluated if this exception gets fulfilled
*)}Scope variable definition exception
*)| Error of {error : error;Runtime error itself
*)locs : code_location list;Extra-relevant locations
*)message : string option;User-faced error message
*)}Runtime error description
*)This type describes all the different trace kind generated throughout execution
Variable-kind declaration info, i.e., name and declaration position
type trace = trace_element listand trace_element = {kind : trace_kind;The kind of trace
pos : code_location;The expression pos responsible for this trace
value : Value.t option;The resulting evaluated value. No value present on error.
*)sub_trace : trace;Sub elements of the trace. E.g., a ScopeCall trace will contain ScopeVarDef traces in its sub-trace.
}Trace node
val begin_trace : trace_kind -> code_location -> unitBegins a trace scope given a trace_kind and its code_location.
Ends the currently opened trace scope and register the value.
val single_trace : trace_kind -> code_location -> unitEquivalent to a sequence of begin_trace then end_trace. Used for error reporting.
val with_trace :
embed:('a -> Value.t) ->
trace_kind ->
code_location ->
(unit -> 'a) ->
'aWrapper that takes a function f and insert a begin_trace before f () and a end_trace afterwards. It also retrieves and embeds the computed value.
It also catches runtime's errors and insert a single_trace before re-raising it. When it occurs, a flag is also set so that callers do not catch it again.
Finalize the global trace state and returns the immutable trace value.
module Print : sig ... endThis module is for setting options and internals, use Value.format to print values
module Json : sig ... endThis helper function rounds a rational to the nearest integer. Tie-breaker is the "half away from zero" rule: 0.5 is rounded to 1.0 and -0.5 is rounded to -1.0. This function shall be used anytime rounding is necessary.
val money_of_cents_string : string -> moneyval money_of_units_int : int -> moneyval money_to_float : money -> floatval money_to_string : money -> stringval decimal_of_string : string -> decimalval decimal_to_string : max_prec_digits:int -> decimal -> stringval decimal_of_float : float -> decimalval decimal_to_float : decimal -> floatval integer_of_string : string -> integerval integer_to_string : integer -> stringval integer_to_int : integer -> intval integer_of_int : int -> integerval integer_log2 : integer -> intval date_to_string : date -> stringval date_of_numbers : int -> int -> int -> dateUsage: date_of_numbers year month day.
Raises Failure on invalid inputs
val date_to_years_months_days : date -> int * int * intval duration_of_numbers : int -> int -> int -> durationUsage : duration_of_numbers year mounth day.
val duration_to_years_months_days : duration -> int * int * intval duration_to_string : duration -> stringval handle_exceptions :
('a * code_location) Optional.t array ->
('a * code_location) Optional.tmodule Oper : sig ... endinclude module type of Operval o_length : 'a array -> integerval o_eq : 'a Value.ty -> code_location -> 'a -> 'a -> boolval o_lt : 'a Value.ty -> code_location -> 'a -> 'a -> boolval o_lte : 'a Value.ty -> code_location -> 'a -> 'a -> boolval o_gt : 'a Value.ty -> code_location -> 'a -> 'a -> boolval o_gte : 'a Value.ty -> code_location -> 'a -> 'a -> boolval o_map2 :
code_location ->
('a -> 'b -> 'c) ->
'a array ->
'b array ->
'c arrayval o_reduce : ('a -> 'a -> 'a) -> 'a array -> 'a Optional.tval o_filter : ('a -> bool) -> 'a array -> 'a arrayval o_add_dat_dur : date_rounding -> code_location -> date -> duration -> dateval o_sub_dat_dur : date_rounding -> code_location -> date -> duration -> dateval o_div_int_int : code_location -> integer -> integer -> decimalval o_div_rat_rat : code_location -> decimal -> decimal -> decimalval o_div_mon_mon : code_location -> money -> money -> decimalval o_div_mon_int : code_location -> money -> integer -> moneyval o_div_mon_rat : code_location -> money -> decimal -> moneyval o_div_dur_dur : code_location -> duration -> duration -> decimalval o_find : ('a -> bool) -> 'a array -> 'a Optional.tval o_sort_asc :
'b Value.ty ->
code_location ->
('a -> 'b) ->
'a array ->
'a arrayval o_sort_desc :
'b Value.ty ->
code_location ->
('a -> 'b) ->
'a array ->
'a arrayModules API
val register_module :
string ->
(string * Stdlib.Obj.t) list ->
?types:(string * (module CatalaType)) list ->
hash ->
unitRegisters a module by the given name defining the given bindings. Required for evaluation to be able to access the given values. The last argument is expected to be a hash of the source file and the Catala version, and will in time be used to ensure that the module and the interface are in sync
Returns Ok if it has been registered with the correct hash, Error h if there is a hash mismatch.
Raises Not_found if the module does not exist at all
val lookup_type : (string * string) -> (module CatalaType)