Malcolm Wallace wrote:
Out of interest, without trying it, what do you think this program
should print (the only difference between the 3 functions is the
indentation of the "where" line)?:

main = do print $ f1 1
        print $ f2 1
        print $ f3 1

I reckon it would be "layout error" at line 2.  :-)

f1 x = x + case () of
         () -> x
       where x = 5

To be honest, it goes slightly against my intuition that the pattern-match against () is accepted by the layout rule at all, because it is indented further to the left than the case itself. Landin's original rule was something like "everything strictly to the right and below" belongs to the syntactic construct. This example breaks that principle.

(hmm, in Ian's message it was lined up vertically with the 'case')

anyway, yes, it's a little weird but fine to get used to: the layout-rule basically reacts to "of", "where", "let" and "do", and so it can't even tell what a "beginning" of a construct is, like the word 'case'. ('where', for instance, comes after functions, 'class', 'instance', 'module'...). Nevertheless it (obviously?) needs to be more indented than the enclosing layout-indentation.

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to