Created
March 11, 2013 17:05
-
-
Save daimatz/5135744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (when) | |
import System.IO (hFlush, stdout) | |
-- main = f | |
main = g | |
f :: IO () | |
f = do | |
x <- getLine | |
when (x /= "q") $ do | |
putStrLn x | |
f | |
g :: IO () | |
g = do | |
_ <- foldl h (return True) acts | |
return () | |
where | |
h :: IO Bool -> IO String -> IO Bool | |
h b act = do | |
b_ <- b | |
if b_ | |
then do | |
x <- act | |
if x == "q" | |
then return False | |
else do | |
putStrLn x | |
hFlush stdout | |
return True | |
else | |
return False | |
-- acts = repeat getLine | |
acts = replicate 5 getLine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment