Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Demo of Either as a Monad for annotated return types.
meow = Right "Meow"
greeting = Right "Hi"
sub_meow input = do
value <- integer_meow input
if value > 7 then
Right "Big Meow"
Left "Too Small"
integer_meow 42 = Right 10
integer_meow value = Left "Wrong input"
someThing = do
sub_meow 42
sub_meow 17 -- Remove this to make things succeed
main = case someThing of
(Left error) -> putStrLn ("Woah baby, error: " ++ error)
(Right result) -> putStrLn ("Success! " ++ result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment