writing a function to build a list of ints from user input

sashan sashang@ihug.co.nz
Tue, 06 May 2003 21:05:46 +0000


I'm trying to write a function that builds a list from user input. This 
is what I've come up with so far.

--a program that makes a list of numbers from user input
makeList :: IO [Int]
makeList = do s <- getLine             
                      if read s /= 0 then return (read s:makeList) else 
return []

However it fails with the following error:
Couldn't match `[a]' against `IO [Int]'
    Expected type: [a]
    Inferred type: IO [Int]
    In the second argument of `(:)', namely `makeList'
    In the first argument of `return', namely `((read s) : makeList)'

It's trying to match a list, [a], with type IO [Int]. This causes it to 
fail. How do I get around this?

-- 
sashan
http://sashan.netfirms.com
---------------------------
Brain: Here we are, Pinky--at the dawn of time!
Pinky:  Narf, Brain.  Wake me at the noon of time.