fork download
  1. ask :: String -> IO String
  2. ask s = putStrLn s >> getLine
  3.  
  4.  
  5. f :: IO String
  6. f =
  7. ask "What's your name ?" >>= \name ->
  8. putStrLn "Write something." >>= \_ ->
  9. getLine >>= \string ->
  10. putStrLn ("Hello " ++ name ++ " you wrote " ++ string) >>= \_ ->
  11. return name
  12.  
  13. g :: IO String
  14. g = do
  15. name <- ask "What's your name ?"
  16. putStrLn "Write something."
  17. string <- getLine
  18. putStrLn ("Hello " ++ name ++ " you wrote " ++ string)
  19. return name
  20.  
  21. -- main = f
  22. main = g
  23.  
Success #stdin #stdout 0s 5696KB
stdin
MyName
Something!
stdout
What's your name ?
Write something.
Hello MyName you wrote Something!