Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created October 27, 2013 16:57
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 joseanpg/7184946 to your computer and use it in GitHub Desktop.
Save joseanpg/7184946 to your computer and use it in GitHub Desktop.
data Maybe a = Nothing | Just a
bind :: Maybe a -> (a -> Maybe b) -> Maybe b
bind m f = case m of
Just x -> f x
Nothing -> Nothing
return :: a -> Maybe a
return x = Just x
mzero :: Maybe ()
mzero = Just ()
delay :: Thunk (Maybe a) -> Thunk (Maybe a)
delay f = f
combine :: Maybe a -> Thunk (Maybe a) -> Maybe a
combine m f = bind m f
run :: Thunk (Maybe a) -> Maybe a
run f = f ()
while :: Thunk Bool -> Thunk (Maybe a) -> Maybe a
while cond f = if cond () then bind f () fun _ -> while cond f
else zero()
let maybe = OptionBuilder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment