Skip to content

Instantly share code, notes, and snippets.

@sadache
Created March 28, 2010 04:28
Show Gist options
  • Save sadache/346569 to your computer and use it in GitHub Desktop.
Save sadache/346569 to your computer and use it in GitHub Desktop.
module Main (
) where
import Control.Monad.Either
f :: (Monad m) ⇒ Int → m Int
f 0 = fail "I don't like zeros"
f x = return x
example1 m =
case m of
Nothing → putStrLn "Nothing"
Just i → putStrLn (show i)
example2 m=
case m of
Left msg → putStrLn msg
Right i → putStrLn (show i)
intermediate :: (Monad m) ⇒ m Int
intermediate= f 0 ↠ λ i → return (i+1)
main = example1 intermediate >> example2 intermediate --prints Nothing
--Example: I don't like zeros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment