Pattern exhaustivity check for simple arithmetic
Motivation
The following:
foo :: Int > Bool
foo i
 i < 0 = True
 i == 0 = True
 i > 0 = True
results on the following warning:
Pattern match(es) are nonexhaustive
In an equation for ‘foo’: Patterns not matched: _

2  foo i
 ^^^^^...
When the guard is indeed exhaustive. One solution is to replace the latest case by otherwise
, but more often than never it leads to subtle bug when a case was indeed missing.
Proposal
I'd like the exhaustivity checker to not complain in this case.
However I realize that it is not a trivial task. I know that it is exhaustive because I know the mathematical rules of comparison for integer, but GHC has no reason to think that it is exhaustive. Actually, someone could implement really weird Eq
and Ord
instances which makes this guard not exhaustive.
May it be possible to extend the COMPLETE
pragma for some instances and using variables? For example (imaginary syntax):
{# COMPLETE forall x :: Int. (<x) (>x) (==x) #}
 For symmetry
{# COMPLETE forall x :: Int. (x<) (x>) (x==) #}