Skip to content

Instantly share code, notes, and snippets.

@psycotica0 psycotica0/test.hs

Last active Aug 29, 2015
Embed
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"
else
Left "Too Small"
integer_meow 42 = Right 10
integer_meow value = Left "Wrong input"
someThing = do
meow
greeting
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
You can’t perform that action at this time.