
Here's a code fragment I have from working with Hal Daume's "Yet Another Haskell Tutorial". I cannot figure out how to iterate over the result from askForNumbers that returns "IO [Integer]", and print them. The "<-" operator seems to take IO off of the results from actions like getContents, which returns type "IO String", but I cannot seem to use it to take IO off of lists with it. What am I supposed to do? Also, as a side question, what should I be returning from the do function?
code>>>>
module Main
where
import IO
main = do
hSetBuffering stdin LineBuffering
s <- askForNumbers {-- This compiles --}
map show s {-- But this doesn't. Why? --}
{-- What expression should I be returning from
do? --}
askForNumbers = do
putStrLn "Give me a number (or 0 to stop):"
guess <- getLine
let number = read guess
if number == 0
then return []
else do
rest <- askForNumbers
return (number : rest)
<<