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

Felipe Lessa felipe.lessa at gmail.com
Tue Aug 10 13:47:51 EDT 2010

On Tue, Aug 10, 2010 at 2:40 PM, Bill Atkins <batkins57 at gmail.com> wrote:
> They're not really statements, they're just named expressions and are still subject to lazy evaluation.
> In:
>  let x = putStrLn "Name" >> getLine
>  putStrLn "Welcome"
>  x

Yes, 'putStrLn "name" >> getLine' is an expression.  However, the
whole line 'let x = putStrLn "Name" >> getLine' inside the
do-block is an statement.  Althought the word 'let' is used in
both cases, they are defined in different places of the grammar
(see the links of my previous mail).

So when you write

  do ...
     let ...  -- stmt

you are using a let statement.  You can use a let expression in a
do-block as well:

  do ...
     let ...
      in ... -- expr

Note, however, that you must indent the 'in' part, as you would
need to indent an if expression inside a do-block.

  do ...                                    do {...
     let ... -- expr    gets parsed as         ;let ... -- stmt
     in ...  --                                ;in ...  -- ???
     ...                                       ;...}



More information about the Haskell-Cafe mailing list