-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecord.sml
65 lines (51 loc) · 1.27 KB
/
record.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
structure Label :> sig
type t
val compare : t * t -> order
val value : val_ident -> t
val module : module_ident -> t
val typ : type_ident -> t
val signature_ : signature_ident -> t
val constr : constr_ident -> t
val encode : t -> string
end = struct
structure Class = struct
datatype t
= V
| M
| T
| S
| C
fun ord V = 0
| ord M = 1
| ord T = 2
| ord S = 3
| ord C = 4
fun compare (x, y) = Int.compare (ord x, ord y)
end
datatype t
= V of val_ident
| M of module_ident
| T of type_ident
| S of signature_ident
| C of constr_ident
fun class (V _) = Class.V
| class (M _) = Class.M
| class (T _) = Class.T
| class (S _) = Class.S
| class (C _) = Class.C
fun compare (x, y) =
case (x, y) of
(V x, V y) => ValID.compare (x, y)
| (M x, M y) => ModuleID.compare (x, y)
| _ => Class.compare (class x, class y)
val value = V
val module = M
val typ = T
val signature_ = S
val constr = C
fun encode (V id) = "V/" ^ ValID.get_name id
| encode (M id) = "M/" ^ ModuleID.get_name id
| encode _ = raise Fail "static components need not to be encoded"
end
type label = Label.t
structure Record = BinarySearchMap Label