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

2006-02-28 Thread Brian Hulley

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

[snip]

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

and

 let
   a = 56
   b = 78
 in a*b

but not

 let a = 56
  b = 78

or

 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. 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2006-02-28 Thread Ben Rudiak-Gould

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 of


keyword clause1
clause2

you can always write

keyword
  clause1
  clause2

or

keyword { clause1
; clause2
}

Both styles are insensitive to tab width and renaming of identifiers. The 
off-side rule only comes into play when you don't include an explicit {, so 
you can suppress it entirely if you prefer.


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. Lisp has similar indentation 
problems despite the lack of a layout rule, since people commonly write


(foo (...)
 (...))

Renaming foo can't confuse the compiler, but I've never had a Haskell layout 
error change the meaning of my program. At worst it causes the program to be 
rejected.


I do edit my source code in a fixed-width font, but it's a very pretty font 
(Bitstream Vera Sans Mono). It's a small price to pay for the convenience of 
being able to use 2D layout, even in languages where it's not significant, 
and in comments.


-- Ben

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe