module Sets (Set, empty, insert, isElem, union) where -- Implementing sets by their characteristic function: data Set a = Set (a -> Bool) empty :: Set a empty = Set (\x -> False) insert :: Eq a => a -> Set a -> Set a insert x (Set fs) = Set (\y -> y==x || fs y) isElem :: Eq a => a -> Set a -> Bool isElem x (Set fs) = fs x union :: Eq a => Set a -> Set a -> Set a union (Set fs1) (Set fs2) = Set (\y -> fs1 y || fs2 y) -- We cannot show functions, thus we provide a trivial instance: instance Show a => Show (Set a) where show _ = "some set"