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

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Mon Jul 9 18:39:49 UTC 2018

> Therefore (if False then a) would give an exception.

Yes. And the question is, why is possible to write
this program using "case" but not with "if".

For the first part (allow incomplete sets of patterns in "case"):

No matter how hard we try, Haskell is not a total language -
there'll always be programs that denote bottom,
by raising exceptions (e.g., from incomplete patterns),
or by non-termination - which cannot be prohibited statically
if we want both the language to be Turing complete,
and type inference to be decidable.

Cf. Agda, which is total, and therefore
has a coverage checker (for patterns)
as well as a termination checker.

But then the second part (do not allow incomplete "if")
appears to be an inconsistency in the design.

Mind you - I don't propose to change this.
The question is just about justification for the design.

Are there applications for an incomplete "if"?
I can imagine something like assertions,
as in "f x = if some-precondition x then some-computation x"
Of course, that's only helpful if the exception
contains source information.

- J.W.

More information about the Haskell-Cafe mailing list