[Haskell-cafe] if-then without -else?

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Mon Jul 9 17:20:11 UTC 2018


Dear Cafe,

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.

For reference, Scheme has short-if, see
http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.4.3
(value is "unspecified" if condition is false)
and Common LISP does as well
https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node84.html#SECTION001160000000000000000
(value is "nil")

Was this considered at some point in Haskell's design process?
There is Section 5.2 on pattern matching in
http://haskell.cs.yale.edu/wp-content/uploads/2011/02/history.pdf (*)
but it does not mention if-then(-else).

- J.W.

(*) can we please add this to https://www.haskell.org/documentation
Upvote this: https://github.com/haskell-infra/hl/issues/86


More information about the Haskell-Cafe mailing list