2021-01-30 19:54:05 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax and social benefits
|
2021-05-29 19:18:46 +03:00
|
|
|
computation rules. Copyright (C) 2020 Inria, contributors: Denis Merigoux
|
|
|
|
<denis.merigoux@inria.fr>, Emile Rolley <emile.rolley@tuta.io>
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
|
|
in compliance with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
or implied. See the License for the specific language governing permissions and limitations under
|
|
|
|
the License. *)
|
|
|
|
|
|
|
|
(** {1 Types} *)
|
|
|
|
|
|
|
|
type money
|
|
|
|
|
|
|
|
type integer
|
|
|
|
|
|
|
|
type decimal
|
|
|
|
|
|
|
|
type date
|
|
|
|
|
|
|
|
type duration
|
|
|
|
|
2021-06-09 01:21:06 +03:00
|
|
|
type source_position = {
|
|
|
|
filename : string;
|
|
|
|
start_line : int;
|
|
|
|
start_column : int;
|
|
|
|
end_line : int;
|
|
|
|
end_column : int;
|
|
|
|
law_headings : string list;
|
|
|
|
}
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
(** {1 Exceptions} *)
|
|
|
|
|
|
|
|
exception EmptyError
|
|
|
|
|
|
|
|
exception AssertionFailed
|
|
|
|
|
|
|
|
exception ConflictError
|
|
|
|
|
|
|
|
exception UncomparableDurations
|
|
|
|
|
2021-05-29 19:18:46 +03:00
|
|
|
exception IndivisableDurations
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
exception ImpossibleDate
|
|
|
|
|
2021-06-09 01:21:06 +03:00
|
|
|
exception NoValueProvided of source_position
|
|
|
|
|
2021-04-04 17:57:59 +03:00
|
|
|
(** {1 Value Embedding} *)
|
|
|
|
|
|
|
|
type runtime_value =
|
2021-04-05 20:06:32 +03:00
|
|
|
| Unit
|
|
|
|
| Bool of bool
|
2021-04-04 17:57:59 +03:00
|
|
|
| Money of money
|
|
|
|
| Integer of integer
|
|
|
|
| Decimal of decimal
|
|
|
|
| Date of date
|
|
|
|
| Duration of duration
|
2021-04-09 00:23:10 +03:00
|
|
|
| Enum of string list * (string * runtime_value)
|
2021-04-04 17:57:59 +03:00
|
|
|
| Struct of string list * (string * runtime_value) list
|
2021-04-09 00:23:10 +03:00
|
|
|
| Array of runtime_value Array.t
|
2021-04-04 17:57:59 +03:00
|
|
|
| Unembeddable
|
|
|
|
|
|
|
|
val unembeddable : 'a -> runtime_value
|
|
|
|
|
2021-04-05 20:06:32 +03:00
|
|
|
val embed_unit : unit -> runtime_value
|
|
|
|
|
|
|
|
val embed_bool : bool -> runtime_value
|
|
|
|
|
|
|
|
val embed_money : money -> runtime_value
|
|
|
|
|
|
|
|
val embed_integer : integer -> runtime_value
|
|
|
|
|
|
|
|
val embed_decimal : decimal -> runtime_value
|
|
|
|
|
|
|
|
val embed_date : date -> runtime_value
|
|
|
|
|
|
|
|
val embed_duration : duration -> runtime_value
|
|
|
|
|
2021-04-09 00:23:10 +03:00
|
|
|
val embed_array : ('a -> runtime_value) -> 'a Array.t -> runtime_value
|
|
|
|
|
2021-04-03 18:58:31 +03:00
|
|
|
(** {1 Logging} *)
|
|
|
|
|
|
|
|
type event =
|
2021-04-05 20:06:32 +03:00
|
|
|
| BeginCall of string list
|
|
|
|
| EndCall of string list
|
2021-04-04 17:57:59 +03:00
|
|
|
| VariableDefinition of string list * runtime_value
|
2021-04-03 18:58:31 +03:00
|
|
|
| DecisionTaken of source_position
|
|
|
|
|
|
|
|
val reset_log : unit -> unit
|
|
|
|
|
|
|
|
val retrieve_log : unit -> event list
|
|
|
|
|
2021-04-05 20:06:32 +03:00
|
|
|
val log_begin_call : string list -> ('a -> 'b) -> 'a -> 'b
|
2021-04-03 18:58:31 +03:00
|
|
|
|
2021-04-05 20:06:32 +03:00
|
|
|
val log_end_call : string list -> 'a -> 'a
|
2021-04-03 18:58:31 +03:00
|
|
|
|
2021-04-04 17:57:59 +03:00
|
|
|
val log_variable_definition : string list -> ('a -> runtime_value) -> 'a -> 'a
|
2021-04-03 18:58:31 +03:00
|
|
|
|
|
|
|
val log_decision_taken : source_position -> bool -> bool
|
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
(**{1 Constructors and conversions} *)
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
(**{2 Money}*)
|
|
|
|
|
|
|
|
val money_of_cents_string : string -> money
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val money_of_units_int : int -> money
|
|
|
|
|
|
|
|
val money_of_cents_integer : integer -> money
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val money_to_float : money -> float
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val money_to_string : money -> string
|
|
|
|
|
|
|
|
val money_to_cents : money -> integer
|
|
|
|
|
|
|
|
(** {2 Decimals} *)
|
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
val decimal_of_string : string -> decimal
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val decimal_to_string : max_prec_digits:int -> decimal -> string
|
|
|
|
|
|
|
|
val decimal_of_integer : integer -> decimal
|
|
|
|
|
|
|
|
val decimal_of_float : float -> decimal
|
|
|
|
|
|
|
|
val decimal_to_float : decimal -> float
|
|
|
|
|
|
|
|
(**{2 Integers} *)
|
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
val integer_of_string : string -> integer
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val integer_to_string : integer -> string
|
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
val integer_to_int : integer -> int
|
|
|
|
|
|
|
|
val integer_of_int : int -> integer
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val integer_log2 : integer -> int
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val integer_exponentiation : integer -> int -> integer
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
(**{2 Dates} *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val day_of_month_of_date : date -> integer
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val month_number_of_date : date -> integer
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val year_of_date : date -> integer
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val date_to_string : date -> string
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val date_of_numbers : int -> int -> int -> date
|
|
|
|
(** Usage: [date_of_numbers year month day]
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
@raise ImpossibleDate *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
(**{2 Durations} *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val duration_of_numbers : int -> int -> int -> duration
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-06-20 23:07:39 +03:00
|
|
|
val duration_to_years_months_days : duration -> int * int * int
|
2021-03-05 21:16:56 +03:00
|
|
|
|
|
|
|
val duration_to_string : duration -> string
|
|
|
|
|
|
|
|
(**{1 Defaults} *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val handle_default : (unit -> 'a) array -> (unit -> bool) -> (unit -> 'a) -> 'a
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise EmptyError
|
|
|
|
@raise ConflictError *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val no_input : unit -> 'a
|
|
|
|
|
|
|
|
(**{1 Operators} *)
|
|
|
|
|
2021-03-10 18:42:48 +03:00
|
|
|
(**{2 Money} *)
|
2021-03-05 21:16:56 +03:00
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
val ( *$ ) : money -> decimal -> money
|
|
|
|
|
|
|
|
val ( /$ ) : money -> money -> decimal
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise Division_by_zero *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val ( +$ ) : money -> money -> money
|
|
|
|
|
|
|
|
val ( -$ ) : money -> money -> money
|
|
|
|
|
|
|
|
val ( ~-$ ) : money -> money
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( =$ ) : money -> money -> bool
|
|
|
|
|
|
|
|
val ( <=$ ) : money -> money -> bool
|
|
|
|
|
|
|
|
val ( >=$ ) : money -> money -> bool
|
|
|
|
|
|
|
|
val ( <$ ) : money -> money -> bool
|
|
|
|
|
|
|
|
val ( >$ ) : money -> money -> bool
|
|
|
|
|
|
|
|
(**{2 Integers} *)
|
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
val ( +! ) : integer -> integer -> integer
|
|
|
|
|
|
|
|
val ( -! ) : integer -> integer -> integer
|
|
|
|
|
|
|
|
val ( ~-! ) : integer -> integer
|
|
|
|
|
|
|
|
val ( *! ) : integer -> integer -> integer
|
|
|
|
|
|
|
|
val ( /! ) : integer -> integer -> integer
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise Division_by_zero *)
|
|
|
|
|
|
|
|
val ( =! ) : integer -> integer -> bool
|
|
|
|
|
|
|
|
val ( >=! ) : integer -> integer -> bool
|
|
|
|
|
|
|
|
val ( <=! ) : integer -> integer -> bool
|
|
|
|
|
|
|
|
val ( >! ) : integer -> integer -> bool
|
|
|
|
|
|
|
|
val ( <! ) : integer -> integer -> bool
|
|
|
|
|
|
|
|
(** {2 Decimals} *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val ( +& ) : decimal -> decimal -> decimal
|
|
|
|
|
|
|
|
val ( -& ) : decimal -> decimal -> decimal
|
|
|
|
|
|
|
|
val ( ~-& ) : decimal -> decimal
|
|
|
|
|
|
|
|
val ( *& ) : decimal -> decimal -> decimal
|
|
|
|
|
|
|
|
val ( /& ) : decimal -> decimal -> decimal
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise Division_by_zero *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( =& ) : decimal -> decimal -> bool
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( >=& ) : decimal -> decimal -> bool
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( <=& ) : decimal -> decimal -> bool
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( >& ) : decimal -> decimal -> bool
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( <& ) : decimal -> decimal -> bool
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
(** {2 Dates} *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( +@ ) : date -> duration -> date
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( -@ ) : date -> date -> duration
|
2021-01-30 19:54:05 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( =@ ) : date -> date -> bool
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val ( >=@ ) : date -> date -> bool
|
|
|
|
|
|
|
|
val ( <=@ ) : date -> date -> bool
|
|
|
|
|
|
|
|
val ( >@ ) : date -> date -> bool
|
|
|
|
|
|
|
|
val ( <@ ) : date -> date -> bool
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
(** {2 Durations} *)
|
|
|
|
|
|
|
|
val ( +^ ) : duration -> duration -> duration
|
|
|
|
|
|
|
|
val ( -^ ) : duration -> duration -> duration
|
|
|
|
|
2021-05-29 19:18:46 +03:00
|
|
|
val ( /^ ) : duration -> duration -> decimal
|
|
|
|
(** @raise Division_by_zero
|
|
|
|
@raise IndivisableDurations *)
|
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
val ( ~-^ ) : duration -> duration
|
|
|
|
|
|
|
|
val ( =^ ) : duration -> duration -> bool
|
|
|
|
|
2021-01-30 19:54:05 +03:00
|
|
|
val ( >=^ ) : duration -> duration -> bool
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise UncomparableDurations *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val ( <=^ ) : duration -> duration -> bool
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise UncomparableDurations *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val ( >^ ) : duration -> duration -> bool
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise UncomparableDurations *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val ( <^ ) : duration -> duration -> bool
|
2021-03-05 21:16:56 +03:00
|
|
|
(** @raise UncomparableDurations *)
|
|
|
|
|
|
|
|
(** {2 Arrays} *)
|
2021-01-30 19:54:05 +03:00
|
|
|
|
|
|
|
val array_filter : ('a -> bool) -> 'a array -> 'a array
|
|
|
|
|
|
|
|
val array_length : 'a array -> integer
|