Someone recently submitted a bug report to the Hugs list as follows:

>class C a where
>f :: a
>f = undefined

is parsed by Hugs as

>class C a where{
>f :: a
>;f = undefined}

which is incorrect - according to the specification of the layout rule
in the Haskell 98 report, it should be parsed as

>class C a where{
>};f :: a
>;f = undefined

Now, while I can see a vague rationale for the new condition that
definition lists must be indented strictly greater than the current
indentation, it seems to me that this change was not widely announced,
not discussed, and breaks many programs.

For instance, I often use the following styles:

>f a b c =
>  defs x
>  where
>  x = ...

>  case exp of
>  Nothing  -> ...
>  (Just a) -> ...

>  do
>  a <- exp1
>  b <- exp2

all of which are now rejected, even though they seem reasonable enough
to me.  The new rule is also visually inconsistent, because

>module M where
>f :: a
>f = undefined

and

>class M where
>f :: a
>f = undefined

are now parsed differently, despite their apparent similarity.  (For
the curious, the module declaration has an indentation of 0, by virtue
of being the first decl in the file, while the f has indentation 1.)

Can I therefore propose that the new rule is actually a bug in the
Report?  I propose that Section B.4, Note 3, should have its
side-condition changed from n > m  to  n >= m.

On the other hand, if Note 3 is to stand in its current form (n > m),
then the bug is in the explanatory text in the main body of the report
(Section 2.7), which seems to suggest that the n >= m form is to be
understood.  I quote:

  The layout (or "off-side") rule takes effect whenever the open brace
  is omitted after the keyword where, let, do, or of. When this
  happens, the indentation of the next lexeme (whether or not on a new
  line) is remembered and the omitted open brace is inserted (the
  whitespace preceding the lexeme may include comments). For each
  subsequent line, if it contains only whitespace or is indented more,
  then the previous item is continued (nothing is inserted); if it is
  indented the same amount, then a new item begins (a semicolon is
  inserted); and if it is indented less, then the layout list ends (a
  close brace is inserted).

Regards,
    Malcolm



Reply via email to