From: simonpj@microsoft.com Date: Tue, 22 Apr 2008 11:29:25 +0000 (+0000) Subject: Add Note [Generating the in-scope set for a substitution] X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=04baa3c1969bdf1c1f39c4383703d9f5acc77d81 Add Note [Generating the in-scope set for a substitution] --- diff --git a/compiler/types/Type.lhs b/compiler/types/Type.lhs index df9e3c7..db23582 100644 --- a/compiler/types/Type.lhs +++ b/compiler/types/Type.lhs @@ -1258,6 +1258,19 @@ extendTvSubstList (TvSubst in_scope env) tvs tys -- the types given; but it's just a thunk so with a bit of luck -- it'll never be evaluated +-- Note [Generating the in-scope set for a substitution] +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-- If we want to substitute [a -> ty1, b -> ty2] I used to +-- think it was enough to generate an in-scope set that includes +-- fv(ty1,ty2). But that's not enough; we really should also take the +-- free vars of the type we are substituting into! Example: +-- (forall b. (a,b,x)) [a -> List b] +-- Then if we use the in-scope set {b}, there is a danger we will rename +-- the forall'd variable to 'x' by mistake, getting this: +-- (forall x. (List b, x, x) +-- Urk! This means looking at all the calls to mkOpenTvSubst.... + + mkOpenTvSubst :: TvSubstEnv -> TvSubst mkOpenTvSubst env = TvSubst (mkInScopeSet (tyVarsOfTypes (varEnvElts env))) env