
On 2018-07-09 01:20 PM, Johannes Waldmann wrote:
a student in my class detected this inconsistency in the design of Haskell:
Why require that each "if-then" has an "else" while still allowing incomplete sets of patterns? We could define "if p then a" by translating to "case p of { True -> a }"
I think that "but then we'd have the dangling-else problem" is not a good answer because this is really about semantics, not surface syntax.
Anthony Clayden is right that if-then-else has the benefit of giving an unambiguous grammar. if-then can be made unambiguous if you throw in delimiting, e.g., if-then-fi, if-then-begin-end. Suppose you like to support if-then (and have your disambiguation story) on the ground that case-of-True is already supported, and you don't mind the partiality, then why stop there? Why is if-else getting no love from you? Afterall, case-of-False is already supported, too.
:)