Re: Layout syntax

Joachim Durchholz <>
14 Dec 2003 22:10:48 -0500

          From comp.compilers

Related articles
Layout syntax (2003-12-03)
Re: Layout syntax (Joachim Durchholz) (2003-12-08)
Re: Layout syntax (2003-12-13)
Re: Layout syntax (Carl Cerecke) (2003-12-13)
Re: Layout syntax (Joachim Durchholz) (2003-12-14)
Re: Layout syntax (2003-12-20)
Re: Layout syntax (Joachim Durchholz) (2003-12-21)
Re: Layout syntax (2003-12-23)
Re: Layout syntax (Joachim Durchholz) (2003-12-27)
Re: Layout syntax (2004-01-02)
Re: Layout syntax (Joachim Durchholz) (2004-01-07)
[9 later articles]
| List of all articles for this month |

From: Joachim Durchholz <>
Newsgroups: comp.compilers
Date: 14 Dec 2003 22:10:48 -0500
Organization: Oberberg Online Infosysteme
References: 03-12-016 03-12-060 03-12-081
Keywords: syntax
Posted-Date: 14 Dec 2003 22:10:48 EST

Hans Aberg wrote:

> Joachim Durchholz <> wrote:
>>>My impression is that in math, the interpretation of formulas does not
>>>depend on the indentation of new lines; or, at least, I cannot recall
>>>any example where it does. There are certainly formulas with
>>>two-dimensional layouts, like matrices, graphs, diagrams of category
>>>theory and the like. But these do not change semantics with the
>>>indentation level.
>>This is probably because most mathematical objects don't have much of
>>a nested structure.
> Quite on the contrary, pure math has a lot of nested structures, even
> though perhaps not so much in formulas.

Oops - right, mathematical objects tend to be nested, and deeply so.

>> That's also why I think that mathematical tradition isn't a source
>>of inspiration for questions in this specific area.
> I write on a proof-verification system, which is the reason it is a source
> of inspiration to me. :-)

I'm pretty sure that it's more semantic than syntactic inspiration.

>>>Also, formulas that depend on the indentation levels is a common
>>>hurdle for programmers; such errors are hard for humans to
>>>detect. Then one has lost some of the advantages with the
>>>indentation syntax.
>>Any references? I don't know how indentation has been a "common hurdle"
>>with "hard-to-detect errors".
> The source is the Haskell and Hugs mailing lists <>,
> which I followed over a couple of years.
> Indentation errors are not only difficult for humans to detect, they often
> generate incomprehensible compiler error messages as well. One could of
> course argue this has with the compiler to do, and not the layout syntax
> technique. But that was the state of the art when I followed it.

I know of two potential problems with indentation:
1. Equating a tab with eight spaces. This simply doesn't match the way
tabs are laid out, be it in vi, less, or any GUI editor, and you get all
sorts of strange errors that remain incomprehensible until you tell your
editor to display tabs visually.
There have also been comments that "layout is destroyed when taking code
from quoted text in a mailing list"; as far as I understand the problem,
it's just another case of misinterpreting tabs when they go from one
environment to another.
(I'm more and more leaning towards banning tabs. To address memory
storage concerns, one can use a compressing file system; to address
numbers-of-keypresses concerns, one can use an editor that does smart
(un-)indenting and that converts tabs to spaces. It seems that the
reasons for using tabs in files have evaporated.)
2. Haskell makes indentation significant only when it follows specific
keywords. I'm not sure how much of a problem this is in practice, but it
does sound like there's a severe non-orthogonality involved here.

If the indentation problems on the Haskell mailing lists can be traced
back to one of these problems, I'd say they are ephemeral. If there were
indentation problems with other sources, I'd like to hear about them.

> Any syntactic feature that one has to spend a lot of time upon without it
> ever becoming natural is probably wrong anyway.

As Carl wrote, it seems to become natural after a while. There's
another question on the quality of problem messages on the mailing
lists: were these consistently from newbies, or did it bite people
with a degree of familiarity with indentation? Newbie problems can be
attributed to the learning curve, and have a somewhat lower
significance than problems that stay with continued use.

> As for the question of keeping the right indentation, I recall THINK
> Pascal, whose editor made the indentation automatically. That is
> probably a better solution than to link it to the language.

In that case, I don't see much of a difference between editors doing
automatic indentation when a programmer types BEGIN or END, and editors
doing smart (un-)indentation when a programmer types <tab> (to indent)
or <backspace> (remove a tab to unindent).

> I agree that if one should use an indentation system, then one should
> probably avoid a tab-to-space conversion, or make it explicit in the file.

How would "making it explicit" work?
I'm a bit sceptical that this would interact well with editors, but I
might have overlooked something, so I'm interested in what you have in mind.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.