Catala_runtimeThe OCaml runtime.
type date = Dates_calc.datetype duration = Dates_calc.periodmodule Optional : sig ... endtype 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
*)| InvalidDateInvalid year/month/day combination
*)| UncomparableDurationsComparing durations in different units (e.g. months vs. days)
*)| AmbiguousDateRoundingambiguous date computation, and rounding mode was not specified
*)| IndivisibleDurationsDividing durations that are not in days
*)| 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 listtype runtime_value = | Unit| Bool of bool| Money of money| Integer of integer| Decimal of decimal| Date of date| Duration of duration| Enum of string * string * runtime_value| Struct of string * (string * runtime_value) list| Array of runtime_value Stdlib.Array.t| Tuple of runtime_value Stdlib.Array.t| Unembeddableval unembeddable : 'a -> runtime_valueval embed_unit : unit -> runtime_valueval embed_bool : bool -> runtime_valueval embed_money : money -> runtime_valueval embed_integer : integer -> runtime_valueval embed_decimal : decimal -> runtime_valueval embed_date : date -> runtime_valueval embed_duration : duration -> runtime_valueval embed_array : ('a -> runtime_value) -> 'a Stdlib.Array.t -> runtime_valueThe logging is constituted of two phases:
raw_event) during the program execution (see retrieve_log) throught Logging instruments.event).Represents information about a name in the code -- i.e. variable name, subscope name, etc...
It's a list of strings with a length varying from 2 to 3, where:
Scope_name,a_subscope_var.input_varSubscope_name or, the input (resp. output) string -- which corresponds to the input (resp. the output) of a function.type raw_event = | BeginCall of informationSubscope or function call.
*)| EndCall of informationEnd of a subscope or a function call.
*)| VariableDefinition of information * io_log * runtime_valueDefinition of a variable or a function argument.
*)| DecisionTaken of code_locationSource code position of an event.
*)The corresponding grammar of the event type, is the following:
<event> := <fun_call>
| <subscope_call>
| <var_def>
| <var_def_with_fun>
| VariableDefinition
<fun_call> :=
VariableDefinition (function input)
<fun_call_beg>
<event>*
(<var_def> | <var_def_with_fun>) (function output)
EndCall
<var_def_with_fun> :=
/-- DecisionTaken
pos of | <fun_call>+ (function calls needed to compute the variable value)
\-> VariableDefinition
<subscope_call> :=
<sub_var_def>* (sub-scope attributes def)
<sub_call_beg>
<event>+
EndCall
<var_def> := DecisionTaken VariableDefinition(info, _)
(when info.length = 2 && info[1] == "id")
<sub_var_def> := DecisionTaken VariableDefinition(info, _)
(when info.length = 3)
<fun_call_beg> := BeginCall(info)
(when info.length = 2)
<sub_call_beg> := BeginCall(info)
(when info.length = 2 and '.' in info[1])type event = | VarComputation of var_def| FunCall of fun_call| SubScopeCall of {name : information;inputs : var_def list;body : event list;}and var_def = {pos : code_location option;name : information;io : io_log;value : runtime_value;fun_calls : fun_call list option;}and fun_call = {fun_name : information;fun_inputs : var_def list;body : event list;output : var_def;}retrieve_log () returns the current list of collected raw_event.
module EventParser : sig ... endval log_variable_definition :
string list ->
io_log ->
('a -> runtime_value) ->
'a ->
'aval log_decision_taken : code_location -> bool -> boolmodule Json : sig ... endpp_events ~is_first_call ppf events pretty prints in ppf the string representation of events.
If is_first_call is set to true, the formatter will be flush at the end. By default, is_first_call is set to false.
This 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 -> 'a -> boolval o_map2 :
code_location ->
('a -> 'b -> 'c) ->
'a array ->
'b array ->
'c arrayval o_reduce : ('a -> 'a -> 'a) -> (unit -> 'a) -> 'a array -> 'aval 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_lt_dur_dur : code_location -> duration -> duration -> boolval o_lte_dur_dur : code_location -> duration -> duration -> boolval o_gt_dur_dur : code_location -> duration -> duration -> boolval o_gte_dur_dur : code_location -> duration -> duration -> boolval o_eq_dur_dur : code_location -> duration -> duration -> boolModules API
Registers 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