Use newtype pattern in Env

This commit is contained in:
백현웅 2022-02-21 02:15:51 +09:00
parent 019e3d7bd1
commit 1784f83887

14
eval.ml
View file

@ -15,7 +15,7 @@ type value =
and expr = Ast.t and expr = Ast.t
(* environment for eval *) (* environment for eval *)
and env = (string * value) list and env = Env of (string * value) list
exception No_operation exception No_operation
exception Too_many_arguments exception Too_many_arguments
@ -79,16 +79,16 @@ end
module Env = struct module Env = struct
type t = env type t = env
let empty = [] let empty = Env []
let get_opt e name = let get_opt (Env e) name =
List.assoc_opt name e List.assoc_opt name e
let bind v e = let bind v (Env e) =
v::e Env (v::e)
let bind_seq seq e = let bind_seq seq (Env e) =
List.of_seq seq @ e Env (List.of_seq seq @ e)
end end
(* operators *) (* operators *)