DoCon and GHC

Simon Peyton-Jones simonpj at
Thu Jan 3 13:57:02 CET 2013

OK I have tested with today's GHC 7.6.2, which is very slightly later than the release candidate.

When I add (EuclideanRing (UPol k)) to the signature for cubicExt, the whole of demotest compiles.  So that works.

Your misconception is here:

| c) Pol3_  has
|    instance (LinSolvRing (Pol a), CommutativeRing a) =>
|                                               LinSolvRing (UPol (Pol a))
|    But this does not overlap with   Field k => LinSolvRing (UPol k).
|    Because  Pol a  is never of a  Field  nor of  EuclideanRing.

When matching instances, GHC does not take account of the context of the instance. Say you have

	data T a = ...
	data S1 = ...
	data S2 = ...
[a]	instance Num a  => Num (T a) where ...
[b]	instance Show a => Num (T a) where ...
	instance Num S1

and suppose you need an instance of (Num (T S1)). Then although [a] and [b] overlap, you might say we should use [a], since S1 is an instance of Num, but not an instance of Show.  But GHC does not do this.  It matches instances only based on the bit after the "=>". 

I'm sorry, but that's the way it is.  (There are good reasons for this.)

If you don't care which of the overlapping instances is picked, then you can use -XIncoherentInstances.  But you have to set that flag at the *instance declaration* not at the *use* of the instance.  In this case it would be the instance for LinSolvRing (UPol k)


More information about the Glasgow-haskell-users mailing list