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

Olga Ershova blaze at ruddy.ru
Mon Jul 9 18:54:57 UTC 2018


In hindsight, maybe non-exhaustive case expression should be errors, not
warnings. But then adding new constructor to the type could break existing
code in multiple places, even if constructor is never used. Not everybody
ready to pay this price.

For the "if" expressions, condition type is always Bool with two
constructors, so enforcing totality looks like natural choice here.

On Mon, Jul 9, 2018 at 2:40 PM Johannes Waldmann <
johannes.waldmann at htwk-leipzig.de> wrote:

> > 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.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180709/03c1bacf/attachment.html>


More information about the Haskell-Cafe mailing list