- -- Gather type variables to quantify over
- zonkTcTypes (rule_ty : map idType tpl_ids) `thenNF_Tc` \ zonked_tys ->
- let
- tpl_tvs = tyVarsOfTypes zonked_tys
+ -- IMPORTANT! We *quantify* over any dicts that appear in the LHS
+ -- Reason:
+ -- a) The particular dictionary isn't important, because its value
+ -- depends only on the type
+ -- e.g gcd Int $fIntegralInt
+ -- Here we'd like to match against (gcd Int any_d) for any 'any_d'
+ --
+ -- b) We'd like to make available the dictionaries bound
+ -- on the LHS in the RHS, so quantifying over them is good
+ -- See the 'lhs_dicts' in tcSimplifyAndCheck for the RHS
+
+ -- We initially quantify over any tyvars free in *either* the rule
+ -- *or* the bound variables. The latter is important. Consider
+ -- ss (x,(y,z)) = (x,z)
+ -- RULE: forall v. fst (ss v) = fst v
+ -- The type of the rhs of the rule is just a, but v::(a,(b,c))
+ --
+ -- It's still conceivable that there may be type variables mentioned
+ -- in the LHS, but not in the type of the lhs, nor in the binders.
+ -- They'll get zapped to (), but that's over-constraining really.
+ -- Let's see if we get a problem.
+ forall_tvs = tyVarsOfTypes (rule_ty : map idType tpl_ids)