module Sets(Set, empty, insert, isElem, union) where import Test.QuickCheck data Set a = Set (a -> Bool) empty :: Set a empty = Set (\_ -> False) insert :: Eq a => a -> Set a -> Set a insert x (Set f) = Set (\y -> y==x || f y) isElem :: a -> Set a -> Bool isElem x (Set f) = f x union :: Set a -> Set a -> Set a union (Set f1) (Set f2) = Set (\x -> f1 x || f2 x) instance (Eq a, Arbitrary a) => Arbitrary (Set a) where arbitrary = do xs <- arbitrary return ((foldr :: (a->b->b) -> b -> [a] -> b) insert empty xs) instance Show a => Show (Set a) where show _ = "some set"