summaryrefslogtreecommitdiff
path: root/ghc/misc/examples/io/io017/Main.hs
blob: f0a6d3ef3bc1d4194274a58ae28e274bac6c5484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)