Indentation of If-Then-Else
cgibbard at gmail.com
Mon Oct 23 12:02:09 EDT 2006
On 23/10/06, Henning Thielemann <haskell at henning-thielemann.de> wrote:
> I like to convince other programmers of Haskell by telling them, that
> Haskell can abstract so powerful, that you can define your own control
> structures, and consequently most control structures are actually library
> functions. Two people who I explained it this way asked me, why Haskell
> needs the special if-then-else syntax although an equivalent function can
> be provided in an obvious way. "if-then-else" syntax is an exception from
> a simple concept (functions!), which confuses people. They think there
> must be something special in "if-then-else", because it is not just a
> function from the standard libraries. In contrast to that, 'case' is
> something special because of its pattern matching.
Just tell them that the special thing about it is purely syntactical:
you get to delimit the 'then' and 'else' parts more clearly.
> ... still not. What about other compiler writers, text editor developers,
> language tool writers? They all have to respect every small exception. I'm
> currently concerned with HTML - much more exceptions than rules. This is
> no fun, and Haskell's syntax will go the same way. Let if-then-else in
> Haskell for compatibility reasons, and try to get rid of it until
> Haskell-2. But do not endorse its use by new extensions.
Of course I disagree with this course for all the reasons I stated
above. The whole point of having high level programming languages is
so that you can put more work into the tools so that the end user
doesn't have to work as hard. One shouldn't ask "What's easiest to
parse?" but "What's easiest to read and write?".
> Cons are:
> The sketched problem with indentation can be solved without touching the language.
The problem was that something with indentation that worked in one
context, when placed in the context of a do-block, stopped working. I
don't tend to have that problem myself, as I follow a different custom
for indentation, but when newcomers to the language run into such
things, it can be annoying for them, and it looks like something that
ought to work anyway.
> The syntax extension is unnecessary, thus complicates all language tools without need.
Complicates? It's two optional semicolons. This should really add _at
worst_ a few lines of code to anything parsing Haskell properly, it's
an absolutely trivial change.
More information about the Haskell-prime