+ tcSimplifySuperClasses
+%* *
+%************************************************************************
+
+Note [SUPERCLASS-LOOP 1]
+~~~~~~~~~~~~~~~~~~~~~~~~
+We have to be very, very careful when generating superclasses, lest we
+accidentally build a loop. Here's an example:
+
+ class S a
+
+ class S a => C a where { opc :: a -> a }
+ class S b => D b where { opd :: b -> b }
+
+ instance C Int where
+ opc = opd
+
+ instance D Int where
+ opd = opc
+
+From (instance C Int) we get the constraint set {ds1:S Int, dd:D Int}
+Simplifying, we may well get:
+ $dfCInt = :C ds1 (opd dd)
+ dd = $dfDInt
+ ds1 = $p1 dd
+Notice that we spot that we can extract ds1 from dd.
+
+Alas! Alack! We can do the same for (instance D Int):
+
+ $dfDInt = :D ds2 (opc dc)
+ dc = $dfCInt
+ ds2 = $p1 dc
+
+And now we've defined the superclass in terms of itself.
+
+Solution: never generate a superclass selectors at all when
+satisfying the superclass context of an instance declaration.
+
+Two more nasty cases are in
+ tcrun021
+ tcrun033
+
+\begin{code}
+tcSimplifySuperClasses qtvs givens sc_wanteds
+ = ASSERT( all isSkolemTyVar qtvs )
+ do { (_, frees, binds1) <- tcSimplCheck doc get_qtvs NoSCs givens sc_wanteds
+ ; binds2 <- tc_simplify_top doc False NoSCs frees
+ ; return (binds1 `unionBags` binds2) }
+ where
+ get_qtvs = return (mkVarSet qtvs)
+ doc = ptext SLIT("instance declaration superclass context")
+\end{code}
+
+
+%************************************************************************
+%* *