Indentation of If-Then-Else
Cale Gibbard
cgibbard at gmail.com
Mon Oct 23 12:24:03 EDT 2006
On 23/10/06, Henning Thielemann <haskell at henning-thielemann.de> wrote:
> Cale Gibbard cgibbard at gmail.com, Sun Oct 22 12:23:18 EDT 2006
>
> > The 'then' and 'else' visually separate the parts of the
> > if-expression, and serve to guide one's eyes when reading code
> > silently, and one's words when speaking it aloud.
>
> This argument is true for every function. I don't see why
> if test then a else b
> is necessary, but
> foldr with_function f initial_state i on_list xs
> not.
If-then-else corresponds to a structural part of the English language.
Right folding doesn't. Besides, those are awful names for the parts of
a foldr. The first parameter is the cons replacement and the second
the nil replacement. Having a general syntax for standard
catamorphisms on an algebraic datatype might not be an altogether
terrible idea.
>
> If you really need "then" and "else" we could certainly construct some
> library functions, to let
> if test `then` a `else` b
> work, or
> if (test expression) then (a expression) else (b expression)
>
> Say
> infixr 0 then, else
>
> data Else a = Else a a
>
> else = Else
>
> and so on ...
That seems fairly weak.
Why do you want to break all the Haskell code ever written? Yes,
you're proposing to phase it out, but there's a lot of code which
isn't actively being maintained that would break, and what you're
proposing looks a whole lot worse to (I don't think I'm assuming much)
most Haskell programmers. The changes that you've been proposing to
Haskell make me wonder why it is that you're interested in working
with Haskell in the first place -- it's just not the sort of minimal
language you're looking for. Why do we allow multiple function
equations when case could be used? Why do we allow guards? Why do we
have both let and where? The thing is, if you want to create a
function which does the same thing as if-then-else, and use it, you're
free to do so. By and large, I think that most people would agree that
having the then and else parts clearly delimited in such a common form
of expression helps a good deal with reading and writing the code. If
using an if' function was beneficial, people would be doing it all the
time by now. The syntactic form eliminates excess parentheses, and
gives the eye an easy way to follow the logic, whereas with just a
function, you have to work harder to match parens before you know what
the parts of the expression are.
More information about the Haskell-prime
mailing list