Skip to content

Instantly share code, notes, and snippets.

@joker1007
Created July 31, 2012 11:55
Show Gist options
  • Save joker1007/3216436 to your computer and use it in GitHub Desktop.
Save joker1007/3216436 to your computer and use it in GitHub Desktop.
module MyMaybe where
data MyMaybe a = MyJust a | MyNothing deriving Show
instance Monad MyMaybe where
return m = MyJust m
(>>=) m f = case m of
MyJust a -> f a
MyNothing -> MyNothing
mylookup :: (Eq k) => k -> [(k, v)] -> MyMaybe v
mylookup k ms = foldr (\(key, v) acc -> if k == key then MyJust v else acc) MyNothing ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment