[Haskell-cafe] Couple of questions about *let* within *do*

Daniel Fischer daniel.is.fischer at web.de
Tue Aug 10 13:40:21 EDT 2010

On Tuesday 10 August 2010 19:12:57, michael rice wrote:
> OK, then there's also an implicit *in* after the *let* in this code.


do let x = foo

is desugared to

let x = foo in (bar >> baz)

> Must the implicit (or explicit) *in* actually use the calculated
> value(s)?

No, and if the values aren't used, they're not calculated (unless you force 
the calculation in the bindings, e.g. with bangs).

> And, the monad can "continue on" after the *let* (with or without the
> *in*) as below, i.e., the *let* needn't be the last statement in the
> *do*?

It *mustn't* be the last statement; the last statement in a do-block must 
be an expression (return blah, putStrLn whatever, ...)

> main = do
>   gen <- getStdGen
>   let code = genCode gen
>   putStrLn $ "Code is " ++ show code
>   putStrLn "..."
> Michael

More information about the Haskell-Cafe mailing list