On Thu, Aug 17, 2006 at 10:18:25AM +0200, Szymon Z??bkiewicz wrote:
> To: haskell-cafe@haskell.org
> From: Szymon Z??bkiewicz <[EMAIL PROTECTED]>
> Date: Thu, 17 Aug 2006 10:18:25 +0200
> Subject: [Haskell-cafe] Last statement in 'do' must be an expression error.
> 
> Hi.
> 
> When trying to compilke this code:
> 
> {...}
> 8.if (a == 0) && (b == 0)
> 9.       then do
> 10.             nr1 <- read (prompt "enter 1. number: ")
> 11.             nr2 <- read (prompt "enter 2. number: ")

each do block needs to evaluate to some value when performed.  if you
have nothing to return, do something like "return ()".  (note this
only works if the type checker is happy with it.  possibly you need to
restructure parts of the code you didn't post, too.)

> 12.       else do
> 13.            let nr1 = a
> 14.                nr2 = b
> {...}
> 
> The compiler tells me thats there's an error on line 10:
> "The last statement in a 'do' construct mesy be an expression"
> 
> Could you tell me how to change it so that the "declaration" of the
> first nr1 and nr2 is still in the "then" block.

what about this code (untested)?

    do
      nr1 <- if a == 0 then read (prompt ":") else return a
      nr2 <- if b == 0 then read (prompt ":") else return b
      ...



hth,
m.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to