module SetsByLists(Set, empty, insert, isElem, union) where import Test.QuickCheck data Set a = Set [a] deriving Show empty :: Set a empty = Set [] insert :: Eq a => a -> Set a -> Set a insert x (Set s) = Set (if x `elem` s then s else x:s) isElem :: Eq a => a -> Set a -> Bool isElem x (Set s) = x `elem` s union :: Eq a => Set a -> Set a -> Set a union (Set []) s2 = s2 union (Set (x:xs)) s2 = insert x (union (Set xs) s2) instance (Eq a, Arbitrary a) => Arbitrary (Set a) where arbitrary = do xs <- arbitrary return ((foldr :: (a->b->b) -> b -> [a] -> b) insert empty xs)