22798
|
1 |
structure ROOT =
|
|
2 |
struct
|
|
3 |
|
|
4 |
structure Code_Generator =
|
|
5 |
struct
|
|
6 |
|
|
7 |
type 'a eq = {op_eq : 'a -> 'a -> bool};
|
|
8 |
fun op_eq (A_:'a eq) = #op_eq A_;
|
|
9 |
|
|
10 |
end; (*struct Code_Generator*)
|
|
11 |
|
|
12 |
structure List =
|
|
13 |
struct
|
|
14 |
|
|
15 |
fun foldr f (x :: xs) a = f x (foldr f xs a)
|
|
16 |
| foldr f [] a = a;
|
|
17 |
|
|
18 |
fun memberl A_ x (y :: ys) =
|
|
19 |
Code_Generator.op_eq A_ x y orelse memberl A_ x ys
|
|
20 |
| memberl A_ x [] = false;
|
|
21 |
|
|
22 |
end; (*struct List*)
|
|
23 |
|
|
24 |
structure Set =
|
|
25 |
struct
|
|
26 |
|
|
27 |
datatype 'a set = Set of 'a list;
|
|
28 |
|
|
29 |
fun opa A_ x (Set xs) = List.memberl A_ x xs;
|
|
30 |
|
|
31 |
val empty : 'a set = Set [];
|
|
32 |
|
|
33 |
fun insert x (Set xs) = Set (x :: xs);
|
|
34 |
|
|
35 |
fun op_Un xs (Set ys) = List.foldr insert ys xs;
|
|
36 |
|
|
37 |
fun union (Set xs) = List.foldr op_Un xs empty;
|
|
38 |
|
|
39 |
end; (*struct Set*)
|
|
40 |
|
|
41 |
end; (*struct ROOT*)
|