
23 Jun
2005
23 Jun
'05
5:58 a.m.
On 6/23/05, kynn@panix.com
getList = do putStrLn "Give me a number (or 0 to stop):" numString <- getLine let num = read numString if num == 0 then return [] else return (num:getList)
This will give you an error as well. 'num' is of type Integer, whereas getList is of type IO [Integer]. So consing an integer with an IO-action returning a list of integer is a type error. Try something like:
if num == 0 then return [] else do rest <- getList return (num:rest)
So if there are more numbers to be read you _run_ the action getList, retrieve the result, and then return that result with the number you just read in front of it. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862