[Haskell-cafe] Re: PrefixMap: code review request

Brian Hulley brianh at metamilk.com
Tue Feb 28 10:04:38 EST 2006

Ben Rudiak-Gould wrote:
> Brian Hulley wrote:
>> Whoever thought up the original Haskell layout rule assumed that
>> people would be happy using a single fixed width font, tabs set to 8
>> spaces, and didn't care about the brittleness of the code (in the
>> face of identifier renamings) it allowed one to write.
> Are you complaining that Haskell permits you to write code with these
> problems, or that it requires you to? The latter is not true. Instead

Just that it allows you to, because this means other people's code (which 
you may be editing) can be brittle.

> If you have a different layout rule in mind I'd be interested in
> hearing it, but I think Haskell's is quite good overall.

Here is my proposed layout rule:

1) All layout keywords (where, of, let, do) must either be followed by a 
single element of the corresponding block type, and explicit block 
introduced by '{', or a layout block whose first line starts on the *next* 
line and whose indentation is accomplished *only* by tabs

In particular, this allows:

          let a = 56 in a*a


                a = 56
                b = 78
          in a*b

but not

          let a = 56
               b = 78


          let a = 56; b = 78
               c = 90

I would also make it that explicit braces are not allowed to switch off the 
layout rule (ie they can be used within a layout), multiline strings would 
not be permitted, and multiline comments would not be permitted (pragmas 
could easily be used just by using --#) (I'd have a special keyword eg 
'{}module' instead of 'module' at the top of a file to switch off layout for 
the whole file if required, but making the presence of the layout rule 
depend on whether or not there are surrounding braces makes life *way* too 
complicated imho)

This would give the following advantages:

1) When you see a ';' you could immediately tell which block it belongs to 
by looking backwards till the next '{'

2) Variable width fonts can be used, or different font faces to represent 
different sorts of identifier eg class names, tycons, value constructors, 
operators like `seq` as opposed to seq etc

3) Using only tabs ensures that vertical alignment goes to the same position 
on the screen regardless of the font and tabs could even have different 
widths just like in a wordprocessor

4) Any keypress has a localised effect on the parse tree of the buffer as a 
whole ( { " no longer kill everything which follows and there would be no 
{- )

5) It paves the way for a much more immersive editing environment, but I 
can't say more about this at the moment because I haven't finished writing 
it yet and it will be a commercial product :-)))

Using my self-imposed layout rule I'm currently editing all my Haskell code 
in a standard text editor using tabs set to 4 spaces and a variable width 
font and have no problems.

Regards, Brian. 

More information about the Haskell-Cafe mailing list