Batching Effects

January 09, 2017

import Data.Monoid ((<>))

getName :: IO (IO ())
getName = do
  putStrLn "Enter your name:"
  name <- return "Haskell" -- getLine
  return $ do
    putStrLn $ "Your name is " ++ name

getAge :: IO (IO ())
getAge = do
  putStrLn "Enter your age:"
  age <- return 6 -- readLn
  return $ do
    putStrLn $ "Your age is " ++ (show age)

main :: IO ()
main = getName <> getAge >>= id

Usage

$ curl -s https://earldouglas.com/notes/haskell-recipes.md |
  codedown sh | sh -s batching-effects.md
Enter your name:
Enter your age:
Your name is Haskell
Your age is 19

References