Skip to content

Instantly share code, notes, and snippets.

@daimatz
Created March 11, 2013 17:05
Show Gist options
  • Save daimatz/5135744 to your computer and use it in GitHub Desktop.
Save daimatz/5135744 to your computer and use it in GitHub Desktop.
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