layout rules for "where"

Sigbjorn Finne sof@galois.com
Fri, 1 Mar 2002 11:08:51 -0800


Hi Zhanyong,

thanks for bringing this up & spurring me on to fix a bug
that I've been bitten and utterly confused by a couple
of times too.

The CVS repository version of Hugs now handles 'empty
nested contexts' correctly, so empty "where" decls are now
handled the way the Haskell98 report prescribes.

H98 layout people: are there other Hugs infelicities wrt. the
spec? Pls let me know if there are, so that this can be sorted
out.

thanks,
--sigbjorn

----- Original Message ----- 
From: "Zhanyong Wan" <zhanyong.wan@yale.edu>
To: <hugs-bugs@haskell.org>
Sent: Thursday, February 07, 2002 11:55
Subject: layout rules for "where"


> Hi,
> 
> The following is a message I sent to haskell.org.  Malcolm Wallace
> suggested this is a hugs bug.  I'm hoping you are interested in this.
> 
> Regards,
> 
> - Zhanyong Wan
> 
> ################################################
> 
> Hi,
> 
> I have been a big fan of Haskell's layout rules, but was got by them
> lately.
> 
> Here's what I was doing.  I wrote something like:
> 
> > foo =
> >   ...
> >   where
> >     bar = ...
> >
> > ...
> > -- 600 lines of Haskell code suppressed
> >
> > baz = ...
> 
> Unsurprisingly, when I load this module in Hugs, I can use baz as it is
> in the top level.
> 
> Later, I had a better implementation for foo, so I no longer needed
> the local definition for bar.  I made the change, but unfortunately
> forgot to remove the "where" keyword, so the code became:
> 
> > foo =
> >   ...
> >   where
> >
> > ...
> > -- 600 lines of Haskell code suppressed
> >
> > baz = ...
> 
> and it compiled!  However, when I tried to use baz, Hugs complained
> that it's undefined.
> 
> Why?  Because the compiler thinks that *all the code* (that is, 600+
> lines) after the dangling "where" is just local definitions to foo.
> 
> I was lucky to spot the source of the problem quickly because I knew I
> recently changed that line, but in general, this kind of error can be
> very hard to locate.  (In my case, the offending code is 600 lines
> away from where the bug is manifested, and the number can be
> arbitrarily high.)  I imagine this would be particularly scary to
> Haskell beginners and may even turn them away.
> 
> Can't we require that a local definition be more indented than the
> enclosing definition?  That way my code would've been rejected by the
> compiler, and the error message (something like "Empty where-clause on
> line xxx") can actually be helpful.
> 
> Alternatively, if the compiler warns about all unused local bindings by
> default (See also the thread "Why is this legal" on the same mailing
> list), it would avoid the vast confusion.
> 
> --
> # Zhanyong Wan     http://pantheon.yale.edu/~zw23/ ____
> # Yale University, Dept of Computer Science       /\___\
> # P.O.Box 208285, New Haven, CT 06520-8285        ||___|
> 
>