import Id ( idType )
import NameSet ( mkNameSet )
import Class ( classBigSig )
-import FunDeps ( oclose, grow, improve )
+import FunDeps ( oclose, grow, improve, pprEquationDoc )
import PrelInfo ( isNumericClass, isCreturnableClass, isCcallishClass )
import Subst ( mkTopTyVarSubst, substTheta, substTy )
--
-- Hence the (irreds ++ frees)
+ -- However, NOTICE that when we are done, we might have some bindings, but
+ -- the final qtvs might be empty. See [NO TYVARS] below.
+
inferLoop doc tau_tvs (irreds ++ frees) `thenTc` \ (qtvs1, frees1, binds1, irreds1) ->
returnTc (qtvs1, frees1, binds `AndMonoBinds` binds1, irreds1)
\end{code}
on both the Lte and If constraints. What we *can't* do is start again
with (Max Z (S x) y)!
+[NO TYVARS]
+
+ class Y a b | a -> b where
+ y :: a -> X b
+
+ instance Y [[a]] a where
+ y ((x:_):_) = X x
+
+ k :: X a -> X a -> X a
+
+ g :: Num a => [X a] -> [X a]
+ g xs = h xs
+ where
+ h ys = ys ++ map (k (y [[0]])) xs
+
+The excitement comes when simplifying the bindings for h. Initially
+try to simplify {y @ [[t1]] t2, 0 @ t1}, with initial qtvs = {t2}.
+From this we get t1:=:t2, but also various bindings. We can't forget
+the bindings (because of [LOOP]), but in fact t1 is what g is
+polymorphic in.
+
\begin{code}
isFreeAndInheritable qtvs inst
= isFree qtvs inst -- Constrains no quantified vars
if null eqns then
returnTc True
else
- traceTc (ptext SLIT("Improve:") <+> vcat (map ppr_eqn eqns)) `thenNF_Tc_`
+ traceTc (ptext SLIT("Improve:") <+> vcat (map pprEquationDoc eqns)) `thenNF_Tc_`
mapTc_ unify eqns `thenTc_`
returnTc False
where
= tcAddErrCtxt doc $
tcInstTyVars (varSetElems qtvs) `thenNF_Tc` \ (_, _, tenv) ->
unifyTauTy (substTy tenv t1) (substTy tenv t2)
- ppr_eqn ((qtvs, t1, t2), doc)
- = vcat [ptext SLIT("forall") <+> braces (pprWithCommas ppr (varSetElems qtvs))
- <+> ppr t1 <+> ptext SLIT(":=:") <+> ppr t2,
- nest 2 doc]
\end{code}
The main context-reduction function is @reduce@. Here's its game plan.