package catala
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=59d0dd01df52c38a4d793b594f067d14
sha512=944b755f8b47cb14920994f03f022cc3ba6cdf5def1ae8ffda00a196fa97dcc5b57baf642a03068b79e949df2a98d5f0218e3358e549be1ff0f1cddda1e5f848
doc/catala.runtime_ocaml/Catala_runtime/index.html
Module Catala_runtimeSource
The OCaml runtime.
Types
type code_location = {filename : string;start_line : int;start_column : int;end_line : int;end_column : int;law_headings : string list;
}type io_input = | NoInput(*For an internal variable defined only in the scope, and does not appear in the input.
*)| OnlyInput(*For variables that should not be redefined in the scope, because they appear in the input.
*)| Reentrant(*For 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.
Exceptions
type error = | AssertionFailed(*An assertion in the program doesn't hold
*)| NoValue(*No computation with valid conditions found
*)| Conflict(*Two different valid computations at that point
*)| DivisionByZero(*The denominator happened to be 0 here
*)| ListEmpty(*Element access on an empty list
*)| NotSameLength(*Traversing multiple lists of different lengths
*)| UncomparableValues(*Equality check or comparison on functions
*)| DateError of string(*Errors related to date and duration computations
*)| Impossible(*The "impossible" keyword was reached
*)
Value Embedding
Runtime type encoding
Polymorphic, structural equality using runtime type information
Polymorphic, structural comparison using runtime type information
Catala types utils
This interface must be supplied to extend the Catala runtime with abstract types
Execution traces
The 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.
Traces types
type trace_kind = | ScopeCall of trace_ident_decl(*Scope 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 string(*Let-binding of a local variable with its name
*)| LocalTupDef of string list(*Let-binding of a local tuple with the name of each binded variable
*)| FunCall of trace_ident_decl(*Function call with its declaration information
*)| BranchingCondition(*Branching condition for an if-then-else or a pattern matching
*)| IfBranching(*Branch taken of the consequence or alternative of an if-then-else
*)| MatchBranching of {}(*Pattern taken of a pattern-matching
*)| Assertion(*Beginning 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
and trace_element = {kind : trace_kind;(*The
*)kindof tracepos : code_location;(*The expression
*)posresponsible for this tracevalue : Value.t option;(*The resulting evaluated value. No value present on error.
*)sub_trace : trace;(*Sub elements of the trace. E.g., a
*)ScopeCalltrace will containScopeVarDeftraces in its sub-trace.
}Trace node
Trace constructors
Begins a trace scope given a trace_kind and its code_location.
Ends the currently opened trace scope and register the value.
Equivalent to a sequence of begin_trace then end_trace. Used for error reporting.
Wrapper 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.
Trace accessors
Finalize the global trace state and returns the immutable trace value.
Pretty printers
This module is for setting options and internals, use Value.format to print values
JSON printers
Constructors and conversions
Rounding
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.
Money
Decimals
Integers
Dates
Usage: date_of_numbers year month day.
Raises Failure on invalid inputs
Durations
Usage : duration_of_numbers year mounth day.
Times
Defaults
val handle_exceptions :
('a * code_location) Optional.t array ->
('a * code_location) Optional.tOperators
Modules API
val register_module :
string ->
(string * 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