Last active
June 12, 2016 19:43
-
-
Save avh4/827b48ea529cfcf3b9973092a958c68d to your computer and use it in GitHub Desktop.
IO Either
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
import Control.Monad.Except (ExceptT, runExceptT) | |
import Data.Functor.Identity (Identity) | |
start :: ExceptT String IO String | |
start = | |
return "start" | |
next1 :: String -> String | |
next1 first = first ++ " next1" | |
next2 :: Monad m => String -> ExceptT String m String | |
next2 first = | |
return $ first ++ " next2" | |
next3 :: String -> ExceptT String IO String | |
next3 first = | |
return $ first ++ " next3" | |
main' :: ExceptT String IO String | |
main' = | |
do | |
a <- start | |
let b = next1 a | |
c <- next2 b | |
d <- next3 c | |
return d | |
main :: IO () | |
main = | |
do | |
result <- runExceptT main' | |
putStrLn $ show result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment