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

J. Garrett Morris jgbm at acm.org
Tue Jul 10 00:11:04 UTC 2018


On Mon, Jul 9, 2018 at 12:20 PM Johannes Waldmann
<johannes.waldmann at htwk-leipzig.de> wrote:
> > 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 }"

Hi Johannes,

`if p then a` can only ever have value `a`, so why not just write `a`
in the first place?

Of course, it could fail to evaluate... but that's not something (as a
Haskell 1.0 program anyway) you could detect or recover.

Incomplete case matches, in contrast, can do meaningful things---to
name parts of a data structure, or perhaps reflecting a
programmer-believed invariant.  Sure, they let in degenerate cases,
like `case p of {True -> a}`, but that's different from adding syntax
to the language that only expresses degenerate cases.

 /g


More information about the Haskell-Cafe mailing list