Haskell 98 Revised

Simon Peyton-Jones simonpj@microsoft.com
Mon, 5 Nov 2001 05:02:16 -0800


Gentle Haskellers

Yes!  The layout rule bites again.  Ian writes:

| Finally, ghci, hi and hugs seem to accept
|
| > module Foo where
| > instance Fractional Int where
| > foo =3D 5

In fact, GHC and Hugs have different interpretations: Hugs
treats the 'foo' as part of the 'where', whereas GHC does not.
Meanwhile the current draft of the report seems just wrong.
The annotated program is:

  module Foo where {1}
  <1> instance Fractional Int where {1}
  <1> foo =3D 5

So when the algorithm hits the {1} on line 2, no case matches except
the catch-all case, so {1} makes it through into the output, which is
A Bad Thing.  None of these pseudo-lexemes should get through=20
to the output.

The "obvious" result is:

  module Foo where {
    instance Fractional Int where {} ;
    foo =3D 5
  }

To fix this, it seems to me that all we need do is to add the following
second clause to L

    L ({n}:ts) (m:ms)  =3D  { : (L ts (n:m:ms))      if n > m, (Note 3)
                       =3D  { : } : L ts (m : ms)    otherwise

This makes sure that the {n} case always has an outcome,=20
and implicitly inserts { } where the layout does not increase.


This is an old chestnut, but all the more reason for knocking it
on the head (to mix metaphors).

Simon