[Haskell-cafe] Indentation woes

Brandon Michael Moore brandon at heave.ugcs.caltech.edu
Fri Jul 27 14:09:28 EDT 2007


On Thu, Jul 26, 2007 at 05:34:32PM -0400, anon wrote:
> 2007/7/26, Stefan O'Rear <stefanor at cox.net>:
> >As for "why", it's just a matter of Haskell Committee taste.  Nothing
> >too deep, just an arbitrary set of rules.
> That's not much of an explanation, is it? I imagine someone must have
> given the matter some thought before describing the layout rule in
> great details in the language report. Perhaps there was a perfectly
> good reason to preclude this kind of code, but I'm afraid I do need a
> reason if I am to understand why.

Part of the reason is that the layout rule is supposed to be somewhat
independent of the rest of the grammar. It's described as a simple
preprocessing state that adds block delimiters { ; } just recongizing
a few keywords that open blocks, and otherwise looking at the indentation
of the first non-whitespace character on lines.

You can allow the syntaxes where something is no less indented than it's
containing block by allowing some optional semicolons in the grammar.
GHC keeps it's parser in compiler/parser/Parser.y.pp It's a Happy
grammar file, it shouldn't be hard to make your change and see how
you like it. I think the "gdrh" nonterminal is the one you want to change,
add another production that allows ';' '|' quals '=' exp

Have fun

Brandon Moore


More information about the Haskell-Cafe mailing list