-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sml
80 lines (60 loc) · 1.65 KB
/
env.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
signature ENV = sig
type t
val initial : t
structure Type : sig
exception Unbound of tvar
val lookup : t -> tvar -> kind
val insert : tvar -> kind -> t -> t
end
structure Val : sig
exception Unbound of var
val lookup : t -> var -> tycon
val insert : var -> tycon -> t -> t
end
structure Module : sig
exception Unbound of mvar
val lookup : t -> mvar -> sign * tvar
val insert : tvar -> mvar -> kind -> sign -> t -> t
end
end
structure Env :> ENV = struct
structure TMap = BinarySearchMap (TVar)
structure VMap = BinarySearchMap (open String type t = string)
structure MMap = VMap :> MAP where type key = string
type t = kind TMap.t * tycon VMap.t * (sign * tvar) MMap.t
val initial : t =
let
val vm = VMap.from_list
[ ("false", TBase BBool)
, ("true", TBase BBool)
]
in
(TMap.empty, vm, MMap.empty)
end
structure Type = struct
exception Unbound of tvar
fun lookup (m, _, _) v =
case TMap.lookup v m of
NONE => raise Unbound v
| SOME x => x
fun insert v x (m, a, b) = (TMap.insert v x m, a, b)
end
structure Module = struct
exception Unbound of mvar
fun lookup (_, _, m) v =
case MMap.lookup v m of
NONE => raise Unbound v
| SOME x => x
fun insert tv mv k s (tm, vm, mm) =
(TMap.insert tv k tm, vm, MMap.insert mv (s, tv) mm)
end
structure Val = struct
exception Unbound of var
fun lookup (_, m, _) v =
case VMap.lookup v m of
NONE => raise Unbound v
| SOME x => x
fun insert v x (a, m, b) = (a, VMap.insert v x m, b)
end
end
type env = Env.t