Hi, all<br><br>I'm new to haskell and currently reading yaht. I find some problems when trying to solve exercise 3.10.<br><br>The
exersices asks to read a list of numbers terminated by a zero, and
figure out the sum and product of the list. My program is as follows:<br>
<br>ex3_10 = do<br> hSetBuffering stdin LineBuffering<br> numbers <- getNumber<br> let sum = foldr (+) 0 numbers<br> product = foldr (*) 1 numbers<br> putStrLn "The sum is " ++ show(sum)<br> putStrLn "The product is " ++ show(product)<br>
<br>getNumber = do<br> putStrLn "Give me a number (or 0 to stop):"<br> num <- getLine<br> if read num == 0<br> then return []<br> else do<br> rest <- getNumber<br> return (read num : rest)<br>
<br>But when i load the program, ghci reports error:<br> Couldn't match expected type `[a]' against inferred type `IO ()'<br> In the first argument of `(++)', namely `putStrLn "The sum is "'<br>
In a stmt of a 'do' expression:<br> putStrLn "The sum is " ++ show (sum)<br><br>And i just don't understand the first sentence. Could you tell what does it mean?<br><br>Thanks for your reply