+tcMatchTy :: TyVarSet -- Template tyvars
+ -> Type -- Template
+ -> Type -- Target
+ -> Maybe TvSubst -- One-shot; in principle the template
+ -- variables could be free in the target
+
+tcMatchTy tmpls ty1 ty2
+ = case match menv emptyTvSubstEnv ty1 ty2 of
+ Just subst_env -> Just (TvSubst in_scope subst_env)
+ Nothing -> Nothing
+ where
+ menv = ME { me_tmpls = tmpls, me_env = mkRnEnv2 in_scope }
+ in_scope = mkInScopeSet (tmpls `unionVarSet` tyVarsOfType ty2)
+ -- We're assuming that all the interesting
+ -- tyvars in tys1 are in tmpls
+