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 //isEqual`:: Dynamic Dynamic -> Bool | Set t
16 //isEqual` (x :: t^) (y :: t^) = x == y
17 //isEqual` _ _ = False
19 isEqual`` :: Dynamic Dynamic -> Bool
20 isEqual`` x y = (fromJust(fromDynamic x)) == (fromJust(fromDynamic y))
22 class Set a | TC, ==, toString a
24 :: Set = Set [Dynamic]
30 where toString (Set a) = abort "toString not implemented"
33 where == a b = nrOfElts a == nrOfElts b && isSubset a b
35 toSet :: a -> Set | Set, == a
36 toSet e = Set [dynamic e]
38 nrOfElts :: Set -> Int
39 nrOfElts (Set a) = length a
41 isEmptySet :: Set -> Bool
42 isEmptySet (Set []) = True
45 memberOfSet :: a Set -> Bool | Set, == a
46 memberOfSet _ (Set []) = False
47 memberOfSet x (Set [(y :: a^):xs]) = x == y || memberOfSet x (Set xs)
48 memberOfSet x (Set [y:xs]) = memberOfSet x (Set xs)
50 dynMemberOfSet :: Dynamic Set -> Bool
51 dynMemberOfSet _ (Set []) = False
52 dynMemberOfSet x (Set [y:xs]) = isEqual x (fromJust(fromDynamic y)) || dynMemberOfSet x (Set xs)
53 //dynMemberOfSet x (Set [y:xs]) = memberOfSet x (Set xs)
55 isSubset :: Set Set -> Bool
56 isSubset a b = (nrOfElts a) == (nrOfElts (intersection a b))
58 isStrictSubset :: Set Set -> Bool
59 isStrictSubset a b = abort "isStrictSubset nog niet geimplementeerd.\n"
61 union :: Set Set -> Set
62 union (Set a) (Set b) = Set (a ++ b)
64 intersection :: Set Set -> Set
65 intersection (Set []) bs = bs
66 intersection as (Set []) = as
67 intersection (Set [a:as]) (Set bs) = Set [a \\ a <- as | not (dynMemberOfSet a (Set bs))]
69 without :: Set Set -> Set
70 without a b = abort "without nog niet geimplementeerd.\n"
73 Start = memberOfSet 2 (toSet 1)