These suggestions would, firstly, break lots of code for little benefit, and secondly, make code harder to read.
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. Certainly, one can define a conditional function if' and decide to use that everywhere to avoid typing 'then' and 'else', but how many people do this? My guess is that almost nobody does this because it only serves to make code harder to read. Also, one could simply use case-expressions, but people still use if-expressions not just for compactness (the difference there is rather slight), but because they don't read the same way. Haskell is not some minimal programming language core intended to be optimised for the simplest possible machine parsing and fewest desugaring steps. It's optimised for human readability and convenience. We have things like do-notation, which while they are not strictly necessary, serve to filter repetitious noise, while delimiting things clearly for the reader, and present an expression in a form which is (often) closer to one's mental model of the meaning. If-expressions match very closely with the way in which one reads their meaning in natural language, are not so difficult for machines to handle, (the current implementations seem to be having no trouble with them) and don't really complicate the language definition all that much. Please don't attack non-problems. On the other hand, I agree that this is usually the "correct" way to layout an if-expression which does not neatly fit on to one line, or where the results are at all lengthy. However, given the fact that there's no chance of ambiguity anyway, I don't consider this to be something for the language itself to enforce. *That* would be needlessly overcomplicating the language definition. It's something for editors to help the user with, perhaps, and it's something for teachers of the language to point out. Otherwise, it's just not all that important, let people use whatever style they like best in whatever circumstance. Neil pointed out lots of reasonable possibilities, here's another: if long && complicated condition then 0 else 42 I don't use that form all that often myself, but it looks reasonable, and I certainly wouldn't want the compiler to reject it. - Cale On 22/10/06, Brian Smith <[EMAIL PROTECTED]> wrote:
I agree with Henning. Reserved syntax for "if" is totally unnecessary in Haskell. It requires three keywords. Its costs (syntax wise) seem much greater than its benefits (which are practically zero). I don't think that it makes sense to make further complicate this unnecessary syntax. Instead, why not work on eliminating the special syntax altogether? For example, make the "then" and "else" keywords optional and schedule them for removal in the next revision. Hennings suggestion that implementations suggest the correct indention is a good one. The existing Haskell implementations do not do a good job diagnosing layout problems. As far as I know, they don't even try to recover from syntax errors at all. I would like to change both of these problems. The proposed layout changes (NondecreasingIndention and DoAndifThenElse and the one for case) should be postponed until more work on error diangosis and recovery has been done. Regards, Brian _______________________________________________ Haskell-prime mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-prime
_______________________________________________ Haskell-prime mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-prime
