Eliminate tabs

Many newbies seems to get their Haskell code layout wrong because their editor uses tab stops that are not 8 spaces wide. The code looks to them exactly as if it were correctly aligned, but according to the Haskell Report it is not. A reasonable proposal would be to outlaw tab characters in source code altogether. Always use spaces for indentation. Most editors can automatically convert from tabs to spaces, and it is better to alert the newbie programmer with a lexical error "tab not permitted", than to leave it to either the parser, or worse, the type system, to complain about something incomprehensible later on.


[added by Simon M] An alternative suggestion is the following: make it an error if the syntactic interpretation of the source code depends on the width of a tab character.


  • small change to the language
  • breaks very little code
  • allows tabs of any width to be used, and code created using one tab width still has the same meaning when viewed with a different tab width


  • more complicated to explain than just disallowing tabs altogether
  • more to implement
  • hard to precicely specify, language syntax extensions would have to be careful not to turn valid programs into invalid one due to this rule.

Concrete implementation idea for the above

leading tabs are tabs that precede the first non-whitespace character on a line.

if leading tabs are present, all leading whitespace must be made up of tabs.

Allow leading tabs only if the current line establishes a new indentation level and all enclosing indentation levels were established with tabs. You must use leading tabs to continue a tab established indentation level, even when you are not adding a new statement but rather continuing the previous line.

any line that contains tabs in a non-leading position may not establish a new indentation level. (as in, the body of a let,where, etc must all be on the current line or start on the next line.)

these rules do not apply to any lines made up completly of whitespace or comments.

whether the rules apply to lines containing PRAGMAs is implementation defined.

Last modified 13 years ago Last modified on Mar 2, 2006 4:07:44 AM