Use newtype pattern in Env
This commit is contained in:
parent
019e3d7bd1
commit
1784f83887
1 changed files with 7 additions and 7 deletions
14
eval.ml
14
eval.ml
|
@ -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 *)
|
||||||
|
|
Loading…
Add table
Reference in a new issue