-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentifier.sml
60 lines (46 loc) · 1.3 KB
/
identifier.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
signature IDENT = sig
type t
val compare : t * t -> order
val equal : t -> t -> bool
val from_string : string -> t
val show : t -> string
structure Map : sig
include MAP where type key = t
exception MissingInLeft of key
exception MissingInRight of key
val app_eq : ('a * 'b -> unit) -> 'a t -> 'b t -> unit (* MissingInLeft, MissingInRight *)
end
end
functor Ident () :> IDENT = struct
type t = string
val compare = String.compare
fun equal x y = x = y
fun from_string s = s
fun show x = x
structure Map = Map (type t = t val compare = compare)
structure Map = struct
open Map
exception MissingInLeft of key
exception MissingInRight of key
fun app_eq f xs ys =
let
fun go (k, x, acc) =
case lookup k acc of
SOME y => delete k acc before f (x, y)
| NONE => raise MissingInRight k
val ys' = fold go ys xs
in
(raise MissingInLeft (#1 (min ys')))
handle Empty => ()
end
end
end
structure ModuleIdent = Ident ()
structure SignatureIdent = Ident ()
structure ValueIdent = Ident ()
structure TypeIdent = Ident ()
type module_ident = ModuleIdent.t
type signature_ident = SignatureIdent.t
type value_ident = ValueIdent.t
type type_ident = TypeIdent.t
type 'a location = module_ident list * 'a