Skip to content

Commit e01fb45

Browse files
committed
[exercise] 10.4
1 parent 0c0d0ce commit e01fb45

File tree

1 file changed

+16
-0
lines changed
  • chapter10-Interactive-programming

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
getInt :: IO Int
2+
getInt = do s <- getLine
3+
return (read s :: Int)
4+
5+
addN :: Int -> IO Int
6+
addN 0 = do return 0
7+
addN n = do m <- getInt
8+
s <- addN (n - 1)
9+
return (m + s)
10+
11+
adder :: IO ()
12+
adder = do putStr "How many numbers? "
13+
n <- getInt
14+
s <- addN n
15+
putStr "The total is "
16+
putStrLn (show s)

0 commit comments

Comments
 (0)