implementation module StdDynSet import StdEnv import StdMaybe import StdDynamic fromDynamic :: Dynamic -> Maybe t | TC t fromDynamic (x :: t^) = Just x fromDynamic other = Nothing isEqual:: Dynamic t -> Bool | Set t isEqual (x :: t^) a = x == a isEqual _ _ = False class Set a | TC, ==, toString a :: Set = Set [Dynamic] instance zero Set where zero = Set [] instance toString Set where toString (Set a) = abort "toString not implemented" instance == Set where == a b = nrOfElts a == nrOfElts b && isSubset a b toSet :: a -> Set | Set, == a toSet e = Set [dynamic e] nrOfElts :: Set -> Int nrOfElts (Set a) = length a isEmptySet :: Set -> Bool isEmptySet (Set []) = True isEmptySet _ = False memberOfSet :: a Set -> Bool | Set, == a memberOfSet _ (Set []) = False memberOfSet x (Set [(y :: a^):xs]) = x == y || memberOfSet x (Set xs) memberOfSet x (Set [y:xs]) = memberOfSet x (Set xs) dynMemberOfSet :: Dynamic Set -> Bool dynMemberOfSet _ (Set []) = False dynMemberOfSet x (Set [y:xs]) = isEqual x (fromJust(fromDynamic y)) || dynMemberOfSet x (Set xs) //dynMemberOfSet x (Set [y:xs]) = memberOfSet x (Set xs) isSubset :: Set Set -> Bool isSubset a b = (nrOfElts a) == (nrOfElts (intersection a b)) isStrictSubset :: Set Set -> Bool isStrictSubset a b = abort "isStrictSubset nog niet geimplementeerd.\n" union :: Set Set -> Set union (Set a) (Set b) = Set (a ++ b) intersection :: Set Set -> Set intersection (Set []) bs = bs intersection as (Set []) = as intersection (Set [a:as]) (Set [(b::t):bs]) = Set [a \\ a <- as | not (dynMemberOfSet a (Set bs))] without :: Set Set -> Set without a b = abort "without nog niet geimplementeerd.\n" //Start :: Set Start = memberOfSet 2 (toSet 1)