module Sets (Set, empty, insert, isElem, union) where -- Implementing sets by their characteristic function: data Set a = Set (a -> Bool) -- A simple show instance (since we cannot really show a function): instance Show a => Show (Set a) where show _ = "some set" empty :: Set a empty = Set (\x -> False) insert :: Eq a => a -> Set a -> Set a insert x (Set fs) = Set (\y -> x==y || 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)