[Haskell-cafe] accessible layout proposal?

Jimmy Hartzell jim at shareyourgifts.net
Tue Sep 22 20:51:59 EDT 2009

> On Sep 22, 2009, at 8:01 PM, Jimmy Hartzell wrote:
>> I am in love with this proposal:
>> http://www.haskell.org/haskellwiki/Accessible_layout_proposal
> I hadn't read it before.  Now that I have, I really do not like
> it.  "Syntactic sugar causes cancer of the semicolon" as Alan
> Perlis once said, and to my taste this proposal definitely
> counts as cancer of the semicolon.  In effect, its purpose
> is to overload vertical white space.
> Any time that you have something where you think you need
> this, it's likely that a better solution is to break what
> you are doing into smaller pieces.

Well, look at code like this:

wrapParens str = concat [

(And yes, I realize you can do something like this with 'printf "(%s)" str'.)

First off, there is a serious issue with the commas. You should at least
be allowed to have a comma after the last element, a la Python. Otherwise,
the last one is randomly special in this list, and in a format like this,
I regularly edit code accidentally leaving off commas, yielding stuff

concat [
   ")"     -- (oops, no comma!)
   lineEnd -- forgot I needed this

which (of course) results in a very confusing type error. Meanwhile, you
have to format your code very awkwardly, as the closing bracket can't be
in the left-most column, and, all in all, you have lots and lots of commas
cluttering up your otherwise clean-looking layout.

You get humans reading the code based off of the physical layout, while
the computer is interpreting it based on the presence of commas, which the
human mind will naturally filter in favor of the layout.

And as to the "simplifying your code" idea: however "pure" your code is,
you will regularly have to embed lists of things in it (ADTs, export
lists, data from the domain). And unless you're claiming it is *almost
always bad style to have code looking like (from the proposal):

main = do
              a <- getChar
                  (enter a)
                  (exit a)
                      putChar a
                      putStrLn "hello")

then the same argument holds for $# (which I expect is the most
controversial part of the proposal): the humans read the layout, the
computers read the parentheses, and there are many opportunities for
error. I mean, probably in this case the code could stand to be changed

with a = bracket_ (enter a) (exit a)
main = do
   a <- getChar
   with a $ do
        putChar a
        putStrLn "hello"

But I would *still* rather have:
with a = bracket_ $#
    enter a
    exit a

Layout is easier to read than parentheses.

In summary, I have to spend a good portion of my time coding Haskell
dealing with the fact that I have a lot of {'s, ['s, and ,'s to keep track
of, and they rarely fit on one line (records, ADTs, lists). I have to
spend a significant amount of my coding time finagling the layout to look
sensible, and I don't think anyone would claim that I just shouldn't use
records or ADTs.

More information about the Haskell-Cafe mailing list