23250
|
1 |
structure HOL =
|
22798
|
2 |
struct
|
|
3 |
|
24421
|
4 |
type 'a eq = {eqop : 'a -> 'a -> bool};
|
|
5 |
fun eqop (A_:'a eq) = #eqop A_;
|
22798
|
6 |
|
23250
|
7 |
end; (*struct HOL*)
|
22798
|
8 |
|
|
9 |
structure List =
|
|
10 |
struct
|
|
11 |
|
|
12 |
fun foldr f (x :: xs) a = f x (foldr f xs a)
|
|
13 |
| foldr f [] a = a;
|
|
14 |
|
24421
|
15 |
fun member A_ x (y :: ys) = HOL.eqop A_ x y orelse member A_ x ys
|
23850
|
16 |
| member A_ x [] = false;
|
22798
|
17 |
|
|
18 |
end; (*struct List*)
|
|
19 |
|
|
20 |
structure Set =
|
|
21 |
struct
|
|
22 |
|
|
23 |
datatype 'a set = Set of 'a list;
|
|
24 |
|
|
25 |
val empty : 'a set = Set [];
|
|
26 |
|
|
27 |
fun insert x (Set xs) = Set (x :: xs);
|
|
28 |
|
24421
|
29 |
fun union xs (Set ys) = List.foldr insert ys xs;
|
23107
|
30 |
|
23850
|
31 |
fun member A_ x (Set xs) = List.member A_ x xs;
|
22798
|
32 |
|
24421
|
33 |
fun uniona (Set xs) = List.foldr union xs empty;
|
|
34 |
|
22798
|
35 |
end; (*struct Set*)
|