check for exhaustive patterns is broken
Feliks Kluzniak
feliks at crt.se
Mon Feb 11 11:37:32 EST 2002
> > Surely, the properties of "<", ">" and "==" are such that the
> > compiler can see there are no other cases?
> No. First, they can be defined for some type such that they aren't
> exhaustive. Second, compilers aren't that smart to infer all possible
> consequences that theoretically are true.
Well.. no! ;-)
In Haskell 98 "Ord" is explicitly limited to _total_ orderings. Even though the
compiler might not be able to detect an instance that defines, say, a partial
ordering, defining such an instance would definitely be asking for trouble
(think about using that type with a library function that uses "compare").
Given the assumption that ordering is total, I am quite sure it would not be
very complicated to make a compiler "smart" enough to handle this case.
> I would replace the last guard with 'otherwise'.
Strangely enough, this particular solution never occurred to me. Not as pretty
as the original, but thanks!
-- F.
More information about the Glasgow-haskell-bugs
mailing list