Created
March 28, 2010 04:28
-
-
Save sadache/346569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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