module SetsAsList (Set, empty, insert, isElem, union) where -- Implementing sets by a list of elements: data Set a = Set [a] deriving Show empty :: Set a empty = Set [] insert :: Eq a => a -> Set a -> Set a insert x (Set xs) = Set (if x `elem` xs then xs else x:xs) isElem :: Eq a => a -> Set a -> Bool isElem x (Set xs) = x `elem` xs union :: Eq a => Set a -> Set a -> Set a union (Set []) s2 = s2 union (Set (x:xs)) s2 = insert x (union (Set xs) s2) -- > quadratic complexity w.r.t. size of the first set!