1 implementation module StdDynSet
7 fromDynamic :: Dynamic -> Maybe t | TC t
8 fromDynamic (x :: t^) = Just x
9 fromDynamic other = Nothing
11 isEqual:: Dynamic t -> Bool | Set t
12 isEqual (x :: t^) a = x == a
15 class Set a | TC, ==, toString a
17 :: Set = Set [Dynamic]
23 where toString (Set a) = abort "toString not implemented"
26 where == a b = nrOfElts a == nrOfElts b && isSubset a b
28 toSet :: a -> Set | Set, == a
29 toSet e = Set [dynamic e]
31 nrOfElts :: Set -> Int
32 nrOfElts (Set a) = length a
34 isEmptySet :: Set -> Bool
35 isEmptySet (Set []) = True
38 memberOfSet :: a Set -> Bool | Set, == a
39 memberOfSet _ (Set []) = False
40 memberOfSet x (Set [(y :: a^):xs]) = x == y || memberOfSet x (Set xs)
41 memberOfSet x (Set [y:xs]) = memberOfSet x (Set xs)
43 dynMemberOfSet :: Dynamic Set -> Bool
44 dynMemberOfSet _ (Set []) = False
45 dynMemberOfSet x (Set [y:xs]) = isEqual x (fromJust(fromDynamic y)) || dynMemberOfSet x (Set xs)
46 //dynMemberOfSet x (Set [y:xs]) = memberOfSet x (Set xs)
48 isSubset :: Set Set -> Bool
49 isSubset a b = (nrOfElts a) == (nrOfElts (intersection a b))
51 isStrictSubset :: Set Set -> Bool
52 isStrictSubset a b = abort "isStrictSubset nog niet geimplementeerd.\n"
54 union :: Set Set -> Set
55 union (Set a) (Set b) = Set (a ++ b)
57 intersection :: Set Set -> Set
58 intersection (Set []) bs = bs
59 intersection as (Set []) = as
60 intersection (Set [a:as]) (Set [(b::t):bs]) = Set [a \\ a <- as | not (dynMemberOfSet a (Set bs))]
62 without :: Set Set -> Set
63 without a b = abort "without nog niet geimplementeerd.\n"
66 Start = memberOfSet 2 (toSet 1)