Question about error message

Seth Kurtzberg
Sat, 17 Aug 2002 12:23:09 -0700

Hello, all

There is an error message that I get from GHCI that I do not understand.  
Usually it is caused by a syntax error or an indentation error, but I have 
occasionally seen it in other contexts and I'd like to understand what it is 
trying to tell me.

The message is that the last statement in a do construct must be an expression 
(exact text below).

I believe this occurs when the last statement in the do construct has a type 
other than "IO ()".  The documentation (or perhaps Simon Thompson's or Paul 
Hudak's book; they get jumbled together in my mind) states that all 
statements in a do construct have type "IO ()"; but this is clearly not 
correct, as in:

    do line <- getLine
        putStrLn line

where the first statement has type IO String.

Here is an example.  This code is useless but it is not obvious to me why it 
is incorrect:

    main = do line <- getLine

producing the error:

<interactive>:1: The last statement in a 'do' construct must be an expression

(This also limits the ability to enter monadic programming to the 

Seth Kurtzberg
M. I. S. Corp
1-480-661-1849 (GMT-7)