[Haskell-beginners] Question re "Pattern match(es) are non-exhaustive"
Brandon Allbery
allbery.b at gmail.com
Tue Feb 10 13:52:24 UTC 2015
On Tue, Feb 10, 2015 at 8:18 AM, Mike Meyer <mwm at mired.org> wrote:
> ghc can't decide whether or not the tests in the guards are complete or
> not.
Expanding on this: that < and >= cover all cases is something that is
convention for Ord instances, not something absolutely guaranteed to be
true. (In fact, they *don't* cover all cases for IEEE floating point math,
if either value is NaN. An SQL numeric value type would also not cover all
cases because of the behavior of NULL. In both those cases, *both*
conditions would return False.) The fact that you specified a type for
which it does happen to be true doesn't really matter, because there's no
way to convey a proof to the compiler that it's true for some types but not
others. (Some argue that this and some other things are signs that the Ord
typeclass is poorly designed; that is a fairly complex discussion.)
A compiler for something like C would assume that it covers all types (and
then behave weirdly in the above mentioned cases. Somewhat infamously,
there was a longstanding bug in a standard C library function (qsort()) for
decades because of this); Haskell compilers are a bit more pedantic and
warn you that Ord provides no proof that those two conditions cover all
cases.
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150210/5db314bd/attachment.html>
More information about the Beginners
mailing list