Szymon Z??bkiewicz wrote:
> The compiler tells me thats there's an error on line 10:
> "The last statement in a 'do' construct must be an expression"

I think, you have reached the point where treating do-notation as magic
won't help you.  Remember, 

> do
>     nr1 <- read (prompt "enter 1. number: ")
>     nr2 <- read (prompt "enter 2. number: ")

is syntactic sugar for

>     read (prompt "enter 1. number: ")         >>= \nr1 ->
>     read (prompt "enter 2. number: ")         >>= \nr2 ->

and it obvious that something is missing after the last arrow.  That's
the expression the compiler is complaining about.  After the
translation, it is also completely clear, that there is no "variable"
which is ever "declared" and could be "assigned".

On a side note, using "trap values" like the special 0 is an ugly style
inherited from C.  You might want to get used to explicit
representations for missing values.  Compare this:

> read_new :: Maybe (Int, Int) -> IO (Int, Int)
> read_new (Just ab) = return ab
> read_new Nothing   = do
>       n1 <- read_prompt "enter 1. number: "
>       n2 <- read_prompt "enter 2. number: "
>       return (n1, n2)
>   where
>     read_prompt p = prompt p >>= readIO

Also note the 'read_prompt' function; I'm pretty sure you got the types
of 'prompt' and 'read' messed up, too.  So in anticipation of your next
question: 'read'ing the 'prompt' action is not the same as 'read'ing the
result of the 'prompt' action.  Only the latter makes sense.


Udo.
-- 
"Enthusiasm is contagious, and so is boredom." -- Paul Graham

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