| Oh ye Haskell wizards.  Is the following program syntactically legal
| or not?
|
| x = let    a = let { b=1;
|         c=2
|                 } in 3
|     in  4
|
| I.e. is the layout rule from an outer scope in effect even inside
| explicit brackets?

Obviously, this needs clarification.  There would seem to be three
possibilities:

        1)  Layout from an outer scope applies even within explicit
            brackets.
        2)  Layout can be used in a nested scope inside explicit brackets,
            but indentations from outside the brackets do not apply.
        3)  Layout is never in effect within explicit brackets.

I favor (3) for its simplicity, although (2) is also sensible.  (1)
seems like a bad idea.

| Here's another
|
| x = let a = let
|   in 3
|     in  4
|
| OK, what happens?  First we insert an lcurl after the first let and
| remember the indentation (8).  Then the second let will get an lcurl
| at indentation 3 (position of in).  But 3 is less than 8 so there also be
| an rcurl from the first let.  The last in will have an rcurl inserted because
| otherwise we would have a syntax error.  So we get
|
| x = let { a = let
|   {}in 3
|     }in  4
|
| This is a correct program, but the curls in the empty let were not inserted
| by matching constructs!!
|
|
|         -- Lennart & Niklas

I think this could be clarified by a slight rewording of the layout rules:
Rather than saying that a layout indentation is established by the first
token other than { following one of the herald keywords, say that anywhere
the grammar has

        { decls }

a layout indentation is established by the first token of  decls , if any,
in the absence of a preceding {.  Thus, in the above example, there is no
layout for the inner let.  Of course, this rule is no longer purely lexical,
but that is the case with inserted }s anyway.


--Joe

Reply via email to