-
Notifications
You must be signed in to change notification settings - Fork 1
/
ord-key-util.sml
36 lines (31 loc) · 1005 Bytes
/
ord-key-util.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
structure IntOrdKey = struct
type ord_key = int
val compare = Int.compare
end
structure StringOrdKey = struct
type ord_key = string
val compare = String.compare
end
structure StringBinaryMap = BinaryMapFn (StringOrdKey)
structure StringListMap = ListMapFn (StringOrdKey)
structure StringBinarySet = BinarySetFn (StringOrdKey)
structure StringListSet = ListSetFn (StringOrdKey)
functor PairOrdKeyFn (structure Fst : ORD_KEY
structure Snd : ORD_KEY) = struct
type ord_key = Fst.ord_key * Snd.ord_key
fun compare ((a, b), (a', b')) =
case Fst.compare (a, a) of
EQUAL => Snd.compare (b, b')
| r => r
end
functor SumOrdKeyFn (structure L : ORD_KEY
structure R : ORD_KEY) = struct
open Util
type ord_key = (L.ord_key, R.ord_key) sum
fun compare (a, a') =
case (a, a') of
(inl _, inr _) => LESS
| (inr _, inl _) => GREATER
| (inl e, inl e') => L.compare (e, e')
| (inr e, inr e') => R.compare (e, e')
end