For learning purposes, I am defining gcd'
function in terms of repeated subtraction:
gcd' :: Integer -> Integer -> Integer
gcd' x y
| x == y = x
| x < y = gcd' x (y - x)
| y < x = gcd' (x - y) y
(Prelude’s gcd function)
The problem is GHC complains about it:
Pattern match(es) are non-exhaustive.
In an equation for ‘gcd’’:
Patterns of type ‘Integer’, ‘Integer’ not matched: _ _
I’ve seen a mathematical law concerning numbers which said:
For all numbers ???? and ????, it is true that either ???? is less than ????, or ???? is less than ????, or ???? equals ????.
In that sense, those three guards cover all possible scenarios. Why is GHC concerned about this definition ?