[Haskell-cafe] newbie - IO issues (of course)

Geoffrey King lordgeoffrey at optushome.com.au
Sat Jun 24 00:38:31 EDT 2006

I have been work my way through "Haskell The Craft of Functional 
Programming", all was fine until IO (chapter 18). That is causing me 

I am trying to write a totally trivial program that reads a series of 
integers from the console until it gets a zero, then returns the series 
of integers as a list.

I am down to randomly editing my code, never a good sign. Any clues 
would be appreciated, My code so far, which clear doesn't work, is:
getInt :: IO Int
getInt = do
            putStr "Enter number (zero to quit)"
            line <- getLine
            return (read line :: Int)

anIntList :: [Int]
anIntList =
            let n = getInt
            if n == 0
                then return []
                else return (n : anIntList)

ps: even a simple version that returns an Int i can't get to work.
anInt :: Int
anInt = do
            n <- getInt
            return n   

More information about the Haskell-Cafe mailing list