-
Notifications
You must be signed in to change notification settings - Fork 6
/
long-id-map.sml
48 lines (39 loc) · 1.05 KB
/
long-id-map.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
structure LongIdMap = struct
open Util
open Expr
fun compare_option cmp (a, a') =
case a of
NONE =>
(case a' of
NONE => EQUAL
| SOME _ => LESS
)
| SOME a =>
(case a' of
NONE => GREATER
| SOME a' => cmp (a, a')
)
fun compare_pair (cmp1, cmp2) ((a, b), (a', b')) =
case cmp1 (a, a') of
EQUAL => cmp2 (b, b')
| ret => ret
fun compare_int (n, n') =
if n < n' then LESS
else if n = n' then EQUAL
else GREATER
fun compare_id (x, x') = compare_int (fst x, fst x')
fun compare_name (x, x') = String.compare (fst x, fst x')
structure LongIdOrdKey = struct
type ord_key = long_id
fun compare (a : long_id, a' : long_id) =
let
fun to_pair id =
case id of
ID x => (NONE, x)
| QID (m, x) => (SOME m, x)
in
compare_pair (compare_option compare_name, compare_id) (to_pair a, to_pair a')
end
end
structure LongIdBinaryMap = BinaryMapFn (LongIdOrdKey)
end