[Haskell-beginners] Re: exercise 3.10 in YAHT

Maurí­cio briqueabraque at yahoo.com
Tue Jun 9 18:26:36 EDT 2009


> loading the file that contains the above function into GHCi (version 
> 6.8.3) gives the following error "The last statement in a 'do' construct 
> must be an expression"
> 
> being a beginner, I'm at a loss at the cause of the error and how to fix 
> it -- any suggestions?
> 
> thanks,
> george

No problem here too, ghc 6.8.2.

Maybe seeing how things are when layout style is not used
helps you see a possible layout problem. Maybe it doesn't,
and you can just forget the example below :)

module Main (main) where {
   getNums = putStrLn "Enter a number (zero to stop):" >> do {
     num <- readLn ;
     if num == 0 then return [] else
       do {rest <- getNums ; return (num:rest)}
   } ;

   main = getNums >>= putStrLn . show
}

Best,
Maurício



More information about the Beginners mailing list