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 ||___|
Zhanyong> I was lucky to spot the source of the problem quickly Zhanyong> because I knew I recently changed that line, but in general, Zhanyong> this kind of error can be very hard to locate. (In my case, Zhanyong> the offending code is 600 lines away from where the bug is Zhanyong> manifested, and the number can be arbitrarily high.) I Zhanyong> imagine this would be particularly scary to Haskell Zhanyong> beginners and may even turn them away. It would turn me away _from layout_ (if I needed being turned away in the 1st place). Not from Haskell. Please, please, please, whatever you do or even suggest doing to layout rules, don't break the non-layout way. -- Ian Zimmerman, Oakland, California, U.S.A. GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087 The world has taken on a thickness of vulgarity that raises a spiritual man's contempt to the violence of a passion. Baudelaire
participants (3)
-
Ian Zimmerman -
Malcolm Wallace -
Zhanyong Wan