From a734413d393f78a1557974830e7717496eb89959 Mon Sep 17 00:00:00 2001 From: adelaett <90894311+adelaett@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:45:06 +0100 Subject: [PATCH] typing default: fix ocaml runtime when using eoption --- compiler/lcalc/to_ocaml.ml | 4 ++-- compiler/shared_ast/expr.ml | 2 +- runtimes/ocaml/runtime.ml | 20 +++++++++++--------- runtimes/ocaml/runtime.mli | 10 ++++++---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/compiler/lcalc/to_ocaml.ml b/compiler/lcalc/to_ocaml.ml index 893fbf3e..78923615 100644 --- a/compiler/lcalc/to_ocaml.ml +++ b/compiler/lcalc/to_ocaml.ml @@ -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 "@[(%a)@] %a" format_typ_with_parens t - format_enum_name Expr.option_enum + Format.fprintf fmt "@[(%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) -> diff --git a/compiler/shared_ast/expr.ml b/compiler/shared_ast/expr.ml index 9e377de7..9817f473 100644 --- a/compiler/shared_ast/expr.ml +++ b/compiler/shared_ast/expr.ml @@ -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) diff --git a/runtimes/ocaml/runtime.ml b/runtimes/ocaml/runtime.ml index 15136ac2..df42e090 100644 --- a/runtimes/ocaml/runtime.ml +++ b/runtimes/ocaml/runtime.ml @@ -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 diff --git a/runtimes/ocaml/runtime.mli b/runtimes/ocaml/runtime.mli index 09e4807d..658e8ceb 100644 --- a/runtimes/ocaml/runtime.mli +++ b/runtimes/ocaml/runtime.mli @@ -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