Skip to content

Instantly share code, notes, and snippets.

@darkf
Created March 21, 2013 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkf/5210283 to your computer and use it in GitHub Desktop.
Save darkf/5210283 to your computer and use it in GitHub Desktop.
More ugly Haskell reimplementation!
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