To reply to your thought process... | DoCon declares | --------------------------------------------------------------- | instance GCDRing Integer ... | instance MulSemigroup (Fraction Integer) where inv_m = ... (1) | ... | inv :: MulSemigroup a -> a -> a | inv a = case inv_m a of ... | | instance GCDRing a => MulSemigroup (Fraction a) where ... (2) | | instance GCDRing a => LinSolvRing (Fraction a) | where | gxBasis ((n:/d):fs) = let ... i = inv (n:/d) in ... | | -- a future fix (b) ------------------ | instance (GCDRing a, MulSemigroup (Fraction a)) => LinSolvRing (Fraction a) | where | gxBasis ((n:/d):fs) = let ... i = inv (n:/d) in ... | --------------------------------------------------------------- | | Integer is a substitutional instance of GCDRing a => a, | Fraction Integer is a substitutional instance of | GCDRing a => Fraction a. | GHC chooses the most special instance (if such is possible to choose in | the situation) among (1) and (2), that is (1). | | But in this example in DoCon, GHC sees the code piece inv (n:/d), | n, d :: GCDRing a => a. | The instance (2) fits. | For the case of a = Integer, the instance (1) would also fit. | GHC must not set (1), because by the context in this code is for a more | generic case.
Correct. The (new) error message says that GHC should not use (2) either, because that commits the instance method to using the more generic version of 'inv'. | If DoCon declares (b), GHC sets here inv of the parameter | instance of MulSemigroup (Fraction a). | For example, suppose that in the further program it meets | gxBasis ([(-2):/3] :: [Fraction Integer]) (E). | | This calls to inv ((-2):/3). | At this point, it has inv_c of MulSemigroup (Fraction Integer), | and has to choose between the instances (1) and (2) for | MulSemigroup (Fraction Integer). | And it chooses (1) as the more special one. | Does GHC act this way? Yes, that's right, if I correctly understand you. | Another point is that ghc-6.8.2 has already reported similar messages | and forced me to set additional contexts of the kind of (b). | Now, ghc-6.10 finds more of such places. | What does this mean? | For example, does this mean that in the above example ghc-6.8.2 sets a | more generic instance (2) for MulSemigroup (Fraction Integer) for (E) ? Yes, it does. And that's a bug really, which 6.10 is fixing. I'll try adding the extra context and see if DoCon 2.11 compiles Simon _______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
