package catala

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

Module Runtime_ocaml.RuntimeSource

The OCaml runtime.

Types

Sourcetype money
Sourcetype integer
Sourcetype decimal
Sourcetype date
Sourcetype duration
Sourcetype source_position = {
  1. filename : string;
  2. start_line : int;
  3. start_column : int;
  4. end_line : int;
  5. end_column : int;
  6. law_headings : string list;
}
Sourceval yojson_of_source_position : source_position -> Ppx_yojson_conv_lib.Yojson.Safe.t
Sourcetype 'a eoption =
  1. | ENone of unit
  2. | ESome of 'a

Exceptions

Sourceexception EmptyError
Sourceexception AssertionFailed of source_position
Sourceexception ConflictError of source_position
Sourceexception UncomparableDurations
Sourceexception IndivisibleDurations
Sourceexception ImpossibleDate
Sourceexception NoValueProvided of source_position

Value Embedding

Sourcetype runtime_value =
  1. | Unit
  2. | Bool of bool
  3. | Money of money
  4. | Integer of integer
  5. | Decimal of decimal
  6. | Date of date
  7. | Duration of duration
  8. | Enum of string list * string * runtime_value
  9. | Struct of string list * (string * runtime_value) list
  10. | Array of runtime_value Array.t
  11. | Unembeddable
Sourceval yojson_of_runtime_value : runtime_value -> Ppx_yojson_conv_lib.Yojson.Safe.t
Sourceval unembeddable : 'a -> runtime_value
Sourceval embed_unit : unit -> runtime_value
Sourceval embed_bool : bool -> runtime_value
Sourceval embed_money : money -> runtime_value
Sourceval embed_integer : integer -> runtime_value
Sourceval embed_decimal : decimal -> runtime_value
Sourceval embed_date : date -> runtime_value
Sourceval embed_duration : duration -> runtime_value
Sourceval embed_array : ('a -> runtime_value) -> 'a Array.t -> runtime_value

Logging

Global process

The logging is constituted of two phases:

  • The first one consists of collecting raw events (see raw_event) during the program execution (see retrieve_log) throught Logging instruments.
  • The second one consists in parsing the collected raw events into structured ones (see event).

Data structures

Sourcetype information = string list

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:

  • the first string is the name of the current scope -- starting with a capitalized letter Scope_name,
  • the second string is either: the name of a scope variable or, the name of a subscope input variable -- a_subscope_var.input_var
  • the third string is either: a subscope name (starting with a capitalized letter Subscope_name or, the input (resp. output) string -- which corresponds to the input (resp. the output) of a function.
Sourceval yojson_of_information : information -> Ppx_yojson_conv_lib.Yojson.Safe.t

The raw events

Sourcetype raw_event =
  1. | BeginCall of information
    (*

    Subscope or function call.

    *)
  2. | EndCall of information
    (*

    End of a subscope or a function call.

    *)
  3. | VariableDefinition of information * runtime_value
    (*

    Definition of a variable or a function argument.

    *)
  4. | DecisionTaken of source_position
    (*

    Source code position of an event.

    *)

The structured events

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])
Sourcetype event =
  1. | VarComputation of var_def
  2. | FunCall of fun_call
  3. | SubScopeCall of {
    1. name : information;
    2. inputs : var_def list;
    3. body : event list;
    }
Sourceand var_def = {
  1. pos : source_position option;
  2. name : information;
  3. value : runtime_value;
  4. fun_calls : fun_call list option;
}
Sourceand fun_call = {
  1. fun_name : information;
  2. inputs : var_def list;
  3. body : event list;
  4. output : var_def;
}
Sourceval yojson_of_event : event -> Ppx_yojson_conv_lib.Yojson.Safe.t
Sourceval yojson_of_var_def : var_def -> Ppx_yojson_conv_lib.Yojson.Safe.t
Sourceval yojson_of_fun_call : fun_call -> Ppx_yojson_conv_lib.Yojson.Safe.t

Parsing

Sourceval retrieve_log : unit -> raw_event list

retrieve_log () returns the current list of collected raw_event.

Sourcemodule EventParser : sig ... end

Helping functions

Logging instruments

Sourceval reset_log : unit -> unit
Sourceval log_begin_call : string list -> 'a -> 'a
Sourceval log_end_call : string list -> 'a -> 'a
Sourceval log_variable_definition : string list -> ('a -> runtime_value) -> 'a -> 'a
Sourceval log_decision_taken : source_position -> bool -> bool

Pretty printers

Sourceval pp_events : ?is_first_call:bool -> Format.formatter -> event list -> unit

pp_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.

Constructors and conversions

Money

Sourceval money_of_cents_string : string -> money
Sourceval money_of_units_int : int -> money
Sourceval money_of_decimal : decimal -> money

Warning: rounds to nearest cent.

Sourceval money_of_cents_integer : integer -> money
Sourceval money_to_float : money -> float
Sourceval money_to_string : money -> string
Sourceval money_to_cents : money -> integer
Sourceval money_round : money -> money

Decimals

Sourceval decimal_of_string : string -> decimal
Sourceval decimal_to_string : max_prec_digits:int -> decimal -> string
Sourceval decimal_of_integer : integer -> decimal
Sourceval decimal_of_float : float -> decimal
Sourceval decimal_to_float : decimal -> float
Sourceval decimal_round : decimal -> decimal
Sourceval decimal_of_money : money -> decimal

Integers

Sourceval integer_of_string : string -> integer
Sourceval integer_to_string : integer -> string
Sourceval integer_to_int : integer -> int
Sourceval integer_of_int : int -> integer
Sourceval integer_log2 : integer -> int
Sourceval integer_exponentiation : integer -> int -> integer

Dates

Sourceval day_of_month_of_date : date -> integer
Sourceval month_number_of_date : date -> integer
Sourceval is_leap_year : integer -> bool
Sourceval year_of_date : date -> integer
Sourceval date_to_string : date -> string
Sourceval date_of_numbers : int -> int -> int -> date

Usage: date_of_numbers year month day

Sourceval first_day_of_month : date -> date
Sourceval last_day_of_month : date -> date

Durations

Sourceval duration_of_numbers : int -> int -> int -> duration

Usage : duration_of_numbers year mounth day.

Sourceval duration_to_years_months_days : duration -> int * int * int

Times

Sourceval duration_to_string : duration -> string

Defaults

Sourceval handle_default : source_position -> (unit -> 'a) array -> (unit -> bool) -> (unit -> 'a) -> 'a
Sourceval handle_default_opt : source_position -> 'a eoption array -> bool eoption -> 'a eoption -> 'a eoption
Sourceval no_input : unit -> 'a

Operators

Sourcemodule Oper : sig ... end
include module type of Oper
Sourceval o_not : bool -> bool
Sourceval o_length : 'a array -> integer
Sourceval o_torat_int : integer -> decimal
Sourceval o_torat_mon : money -> decimal
Sourceval o_tomoney_rat : decimal -> money
Sourceval o_getDay : date -> integer
Sourceval o_getMonth : date -> integer
Sourceval o_getYear : date -> integer
Sourceval o_firstDayOfMonth : date -> date
Sourceval o_lastDayOfMonth : date -> date
Sourceval o_round_mon : money -> money
Sourceval o_round_rat : decimal -> decimal
Sourceval o_minus_int : integer -> integer
Sourceval o_minus_rat : decimal -> decimal
Sourceval o_minus_mon : money -> money
Sourceval o_minus_dur : duration -> duration
Sourceval o_and : bool -> bool -> bool
Sourceval o_or : bool -> bool -> bool
Sourceval o_xor : bool -> bool -> bool
Sourceval o_eq : 'a -> 'a -> bool
Sourceval o_map : ('a -> 'b) -> 'a array -> 'b array
Sourceval o_reduce : ('a -> 'a -> 'a) -> 'a -> 'a array -> 'a
Sourceval o_concat : 'a array -> 'a array -> 'a array
Sourceval o_filter : ('a -> bool) -> 'a array -> 'a array
Sourceval o_add_int_int : integer -> integer -> integer
Sourceval o_add_rat_rat : decimal -> decimal -> decimal
Sourceval o_add_mon_mon : money -> money -> money
Sourceval o_add_dat_dur : date -> duration -> date
Sourceval o_add_dur_dur : duration -> duration -> duration
Sourceval o_sub_int_int : integer -> integer -> integer
Sourceval o_sub_rat_rat : decimal -> decimal -> decimal
Sourceval o_sub_mon_mon : money -> money -> money
Sourceval o_sub_dat_dat : date -> date -> duration
Sourceval o_sub_dat_dur : date -> duration -> date
Sourceval o_sub_dur_dur : duration -> duration -> duration
Sourceval o_mult_int_int : integer -> integer -> integer
Sourceval o_mult_rat_rat : decimal -> decimal -> decimal
Sourceval o_mult_mon_rat : money -> decimal -> money
Sourceval o_mult_dur_int : duration -> integer -> duration
Sourceval o_div_int_int : integer -> integer -> decimal
Sourceval o_div_rat_rat : decimal -> decimal -> decimal
Sourceval o_div_mon_mon : money -> money -> decimal
Sourceval o_div_mon_rat : money -> decimal -> money
Sourceval o_div_dur_dur : duration -> duration -> decimal
Sourceval o_lt_int_int : integer -> integer -> bool
Sourceval o_lt_rat_rat : decimal -> decimal -> bool
Sourceval o_lt_mon_mon : money -> money -> bool
Sourceval o_lt_dur_dur : duration -> duration -> bool
Sourceval o_lt_dat_dat : date -> date -> bool
Sourceval o_lte_int_int : integer -> integer -> bool
Sourceval o_lte_rat_rat : decimal -> decimal -> bool
Sourceval o_lte_mon_mon : money -> money -> bool
Sourceval o_lte_dur_dur : duration -> duration -> bool
Sourceval o_lte_dat_dat : date -> date -> bool
Sourceval o_gt_int_int : integer -> integer -> bool
Sourceval o_gt_rat_rat : decimal -> decimal -> bool
Sourceval o_gt_mon_mon : money -> money -> bool
Sourceval o_gt_dur_dur : duration -> duration -> bool
Sourceval o_gt_dat_dat : date -> date -> bool
Sourceval o_gte_int_int : integer -> integer -> bool
Sourceval o_gte_rat_rat : decimal -> decimal -> bool
Sourceval o_gte_mon_mon : money -> money -> bool
Sourceval o_gte_dur_dur : duration -> duration -> bool
Sourceval o_gte_dat_dat : date -> date -> bool
Sourceval o_eq_int_int : integer -> integer -> bool
Sourceval o_eq_rat_rat : decimal -> decimal -> bool
Sourceval o_eq_mon_mon : money -> money -> bool
Sourceval o_eq_dur_dur : duration -> duration -> bool
Sourceval o_eq_dat_dat : date -> date -> bool
Sourceval o_fold : ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a
OCaml

Innovation. Community. Security.