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

Tillmann Rendel rendel at Mathematik.Uni-Marburg.de
Tue Aug 10 13:35:18 EDT 2010


michael rice wrote:
> OK, then there's also an implicit *in* after the *let* in this code. 

If you want to understand let statements in terms of let ... in ... 
expressions, you can do the following transformation:

   do s1
      s2
      let x1 = e1
          x2 = e2
      s3
      s4

becomes

   do s1
      s2
      let x1 = e1
          x2 = e2 in do s3
                        s4

So in a sense, there is an implicit "in do".

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

No.

By the way, note that lazy evaluation applies, so the expressions bound 
in the let may or may not be evaluated, depending on the rest of the 
program.

> 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*?

Yes, there can be more statements after the let statement. In fact, the 
let statement must not be the last statement in the do-expression, 
because a do-expression has to end with an expression statement. 
Otherwise, what would the result of the do-expression be?

   Tillmann


More information about the Haskell-Cafe mailing list