Read until end of stream in haskell

前端 未结 4 1006
别那么骄傲
别那么骄傲 2021-02-14 00:13

I\'m fairly new to Haskell, and I\'d like to keep reading lines from the console until the end of the stream, and outputting everything I get in upper case. So far, I\'ve got

4条回答
  •  天涯浪人
    2021-02-14 00:50

    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
    

提交回复
热议问题