Created
February 12, 2013 04:28
-
-
Save ehamberg/4760244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Set a = S { insert :: a -> Set a | |
| , member :: a -> Bool | |
| , size :: Int | |
| } | |
| emptySet = let insert xs n = makeSet (if n `elem` xs then xs else n : xs) | |
| member xs n = n `elem` xs | |
| size = length | |
| makeSet xs = S (insert xs) (member xs) (size xs) | |
| in makeSet [] | |
| main :: IO () | |
| main = do | |
| let s1 = emptySet | |
| let s2 = s1 `insert` 8 | |
| let s3 = s2 `insert` 8 | |
| let s4 = s3 `insert` 5 | |
| print $ size s4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment