Read until end of stream in haskell
This goes way beyond what you're really asking for, but I use this pattern a lot: interact
:
myFun :: String -> String
myFun = ...
main = interact (unlines . myFun . lines)
Your function myFun
will be executed against every line of standard input and the result sent to standard output.
Use isEOF
from System.IO
.
import System.IO (isEOF)
import Data.Char
main = myLoop
myLoop = do done <- isEOF
if done
then putStrLn "Bye!"
else do inp <- getLine
putStrLn (map toUpper inp)
myLoop