mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 00:15:39 +03:00
typing default: fix ocaml runtime when using eoption
This commit is contained in:
parent
f254906952
commit
a734413d39
@ -200,8 +200,8 @@ let rec format_typ (fmt : Format.formatter) (typ : typ) : unit =
|
||||
ts
|
||||
| TStruct s -> Format.fprintf fmt "%a.t" format_to_module_name (`Sname s)
|
||||
| TOption t ->
|
||||
Format.fprintf fmt "@[<hov 2>(%a)@] %a" format_typ_with_parens t
|
||||
format_enum_name Expr.option_enum
|
||||
Format.fprintf fmt "@[<hov 2>(%a)@] %a.t" format_typ_with_parens t
|
||||
format_to_module_name (`Ename Expr.option_enum)
|
||||
| TDefault t -> format_typ fmt t
|
||||
| TEnum e -> Format.fprintf fmt "%a.t" format_to_module_name (`Ename e)
|
||||
| TArrow (t1, t2) ->
|
||||
|
@ -255,7 +255,7 @@ let typed = Typed { pos = Pos.no_pos; ty = TLit TUnit, Pos.no_pos }
|
||||
|
||||
(* - Predefined types (option) - *)
|
||||
|
||||
let option_enum = EnumName.fresh [] ("eoption", Pos.no_pos)
|
||||
let option_enum = EnumName.fresh [] ("Eoption", Pos.no_pos)
|
||||
let none_constr = EnumConstructor.fresh ("ENone", Pos.no_pos)
|
||||
let some_constr = EnumConstructor.fresh ("ESome", Pos.no_pos)
|
||||
|
||||
|
@ -25,7 +25,9 @@ type decimal = Q.t
|
||||
type date = Dates_calc.Dates.date
|
||||
type date_rounding = Dates_calc.Dates.date_rounding
|
||||
type duration = Dates_calc.Dates.period
|
||||
type 'a eoption = ENone of unit | ESome of 'a
|
||||
module Eoption = struct
|
||||
type 'a t = ENone of unit | ESome of 'a
|
||||
end
|
||||
type io_input = NoInput | OnlyInput | Reentrant [@@deriving yojson_of]
|
||||
type io_log = { io_input : io_input; io_output : bool } [@@deriving yojson_of]
|
||||
|
||||
@ -591,21 +593,21 @@ let handle_default :
|
||||
|
||||
let handle_default_opt
|
||||
(pos : source_position)
|
||||
(exceptions : 'a eoption array)
|
||||
(exceptions : 'a Eoption.t array)
|
||||
(just : unit -> bool)
|
||||
(cons : unit -> 'a eoption) : 'a eoption =
|
||||
(cons : unit -> 'a Eoption.t) : 'a Eoption.t =
|
||||
let except =
|
||||
Array.fold_left
|
||||
(fun acc except ->
|
||||
match acc, except with
|
||||
| ENone _, _ -> except
|
||||
| ESome _, ENone _ -> acc
|
||||
| ESome _, ESome _ -> raise (ConflictError pos))
|
||||
(ENone ()) exceptions
|
||||
| Eoption.ENone _, _ -> except
|
||||
| Eoption.ESome _, Eoption.ENone _ -> acc
|
||||
| Eoption.ESome _, Eoption.ESome _ -> raise (ConflictError pos))
|
||||
(Eoption.ENone ()) exceptions
|
||||
in
|
||||
match except with
|
||||
| ESome _ -> except
|
||||
| ENone _ -> (if just () then cons () else ENone ())
|
||||
| Eoption.ESome _ -> except
|
||||
| Eoption.ENone _ -> (if just () then cons () else Eoption.ENone ())
|
||||
|
||||
let no_input : unit -> 'a = fun _ -> raise EmptyError
|
||||
|
||||
|
@ -40,7 +40,9 @@ type source_position = {
|
||||
law_headings : string list;
|
||||
}
|
||||
|
||||
type 'a eoption = ENone of unit | ESome of 'a
|
||||
module Eoption : sig
|
||||
type 'a t = ENone of unit | ESome of 'a
|
||||
end
|
||||
|
||||
(** This type characterizes the three levels of visibility for a given scope
|
||||
variable with regards to the scope's input and possible redefinitions inside
|
||||
@ -305,10 +307,10 @@ val handle_default :
|
||||
|
||||
val handle_default_opt :
|
||||
source_position ->
|
||||
'a eoption array ->
|
||||
'a Eoption.t array ->
|
||||
(unit -> bool) ->
|
||||
(unit -> 'a eoption) ->
|
||||
'a eoption
|
||||
(unit -> 'a Eoption.t) ->
|
||||
'a Eoption.t
|
||||
(** @raise ConflictError *)
|
||||
|
||||
val no_input : unit -> 'a
|
||||
|
Loading…
Reference in New Issue
Block a user