-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotdom.sml
36 lines (27 loc) · 866 Bytes
/
protdom.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
structure ProtDom :> PROTDOM =
struct
structure Env = RedBlackMapFn(type ord_key=Id.id
val compare = Id.compareid)
type lattice = (Id.id list) Env.map
type p = Id.id
val empty_prot = Env.empty
fun eq_prot p1 p2 = Id.eqid p1 p2
fun add_prot latt p1 p2 =
let
val latt' = (case Env.find(latt, p2) of
NONE => Env.insert(latt, p2, nil)
| SOME _ => latt)
in
case Env.find(latt,p1) of
NONE => Env.insert(latt', p1, [p2])
| SOME p1s => Env.insert(latt', p1, p2::p1s)
end
fun leq_prot latt p1 p2 =
if (eq_prot p1 p2)
then true
else (case Env.find(latt, p1) of
NONE => false
| SOME p1s => foldr (fn (p,b) => leq_prot latt p p2) false p1s)
fun lattice2string latt =
Env.foldli (fn (p,ps,s) => (foldl (fn(p',s') => Id.id2string p ^ " <= " ^ Id.id2string p' ^ "\n" ^ s')) s ps) "" latt
end