summaryrefslogtreecommitdiff
path: root/libraries/base/tests/IO/hGetChar001.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/tests/IO/hGetChar001.hs')
-rw-r--r--libraries/base/tests/IO/hGetChar001.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/libraries/base/tests/IO/hGetChar001.hs b/libraries/base/tests/IO/hGetChar001.hs
new file mode 100644
index 0000000000..f5ca666828
--- /dev/null
+++ b/libraries/base/tests/IO/hGetChar001.hs
@@ -0,0 +1,18 @@
+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)