summaryrefslogtreecommitdiff
path: root/libraries/base/tests/IO/hGetChar001.hs
blob: f1cd80e6a24d79c9968f05961177e38771583eb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import System.IO

main = do
 hSetBuffering stdout NoBuffering
 putStr   "Enter an integer: "
 x1 <- readLine
 putStr   "Enter another integer: "
 x2 <- readLine
 putStr  ("Their sum is " ++ show (read x1 + read x2 :: Int) ++ "\n")

 where readLine = do
           eof <- isEOF
           if eof
           then return []
           else do
               c <- getChar
               if c `elem` ['\n','\r']
               then return []
               else do
                    cs <- readLine
                    return (c:cs)