week45 mandatory part finished
[fp1415.git] / fp2 / week3 / mart / StdDynSet.icl
1 implementation module StdDynSet
2
3 import StdEnv
4 import StdDynamic
5
6 class Set a | TC, ==, toString a
7
8 :: Set = Set [Dynamic]
9
10 instance zero Set
11 where zero = Set []
12
13 instance toString Set
14 where toString (Set a) = abort "toString not implemented"
15
16 instance == Set
17 where
18 (==) (Set []) (Set []) = True
19 (==) (Set []) _ = False
20 (==) _ (Set []) = False
21
22 toSet :: a -> Set | Set a
23 toSet a = Set [dynamic a]
24
25 nrOfElts :: Set -> Int
26 nrOfElts (Set a) = length a
27
28 isEmptySet :: Set -> Bool
29 isEmptySet (Set []) = True
30 isEmptySet _ = False
31
32 memberOfSet :: a Set -> Bool | Set a
33 memberOfSet _ (Set []) = False
34 memberOfSet x (Set [y:xs])
35 | isEqual x y = True
36 | otherwise = memberOfSet x xs
37
38 isSubset :: Set Set -> Bool
39 isSubset a b = abort "isSubset nog niet geimplementeerd.\n"
40
41 isStrictSubset :: Set Set -> Bool
42 isStrictSubset a b = abort "isStrictSubset nog niet geimplementeerd.\n"
43
44 union :: Set Set -> Set
45 union a b = abort "union nog niet geimplementeerd.\n"
46
47 intersection :: Set Set -> Set
48 intersection a b = abort "intersection nog niet geimplementeerd.\n"
49
50 without :: Set Set -> Set
51 without a b = abort "without nog niet geimplementeerd.\n"
52
53 Start :: Set
54 Start = toSet 1