fno-implicit-prelude and literal numeric patterns

Bernard James POPE bjpop@cs.mu.OZ.AU
Thu, 18 Jul 2002 23:52:39 +1000 (EST)


Hi again,

I know I'm becoming a pest with this, but another question about
-fno-implicit-prelude:

What happens with literal numeric patterns?

For this part of the prelude:

   gcd              :: (Integral a) => a -> a -> a
   gcd 0 0          =  error "Prelude.gcd: gcd 0 0 is undefined"
   gcd x y          =  gcd' (abs x) (abs y)
                       where gcd' x 0  =  x
                             gcd' x y  =  gcd' y (x `rem` y)

I'm getting this error (which refers to the transformed version of the code
of course but I don't think the transformation has anything to do with it).

   Prel_Buddha.hs:459:
       Could not deduce (GHC.Base.Eq a) from the context (Integral a)
       Probable fix:
           Add (GHC.Base.Eq a) to the type signature(s) for `gcd'
       arising from the pattern `0' at Prel_Buddha.hs:459
       When checking the pattern: (0, 0)
       In a case alternative:
           (0, 0) -> error "Prelude.gcd: gcd 0 0 is undefined"

I'm sure my version of class Integral, Real, Num, Eq is the same as the example Prelude
from the Language Report. 

I'm still using 5.03, perhaps it has changed in 5.04? (My apology if it has
- it turns out to be quite hard for me to test in 5.04 because my transformation
doesn't uses the old convention with desugaring do notation ...)

If I get rid of the literal numeric patterns the error disappears.

Cheers,
Bernie.