[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / io / io017 / Main.hs
diff --git a/ghc/misc/examples/io/io017/Main.hs b/ghc/misc/examples/io/io017/Main.hs
new file mode 100644 (file)
index 0000000..f0a6d3e
--- /dev/null
@@ -0,0 +1,17 @@
+main =
+      hSetBuffering stdout NoBuffering                  >>
+      putStr   "Enter an integer: "                     >>
+      readLine                                          >>= \ x1 -> 
+      putStr   "Enter another integer: "                >>
+      readLine                                          >>= \ x2 -> 
+      putStr  ("Their sum is " ++ show (read x1+ read x2) ++ "\n")
+
+ where readLine = isEOF                                 >>= \ eof ->
+                  if eof then return []
+                  else getChar                          >>= \ c ->
+                       if c `elem` ['\n','\r'] then
+                          return []
+                       else
+                          readLine                      >>= \ cs ->
+                          return (c:cs)
+