Created
March 21, 2013 02:35
-
-
Save darkf/5210283 to your computer and use it in GitHub Desktop.
More ugly Haskell reimplementation!
This file contains 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
type Map k v = [(k, v)] | |
newMap :: (Eq k) => [(k, v)] -> Map k v | |
newMap = id | |
mapLookup :: (Eq k) => Map k v -> k -> Maybe v | |
mapLookup [] k = Nothing | |
mapLookup (x:xs) k | |
| fst x == k = Just $ snd x | |
| otherwise = mapLookup xs k | |
out :: (Show a) => Maybe a -> IO () | |
out Nothing = print "not found" | |
out (Just x) = print x | |
main = do out $ mapLookup m "foo" | |
out $ mapLookup m "derp" | |
out $ mapLookup m "hi" | |
where m = newMap [("hi", "there"), | |
("foo", "rooster")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment