+rttiEnvironment :: HscEnv -> IO HscEnv
+rttiEnvironment hsc_env@HscEnv{hsc_IC=ic} = do
+ let InteractiveContext{ic_tmp_ids=tmp_ids, ic_tyvars = tyvars} = ic
+ incompletelyTypedIds =
+ [id | id <- tmp_ids
+ , not $ null [v | v <- varSetElems$ tyVarsOfType (idType id)
+ , isSkolemTyVar v]
+ , (occNameFS.nameOccName.idName) id /= result_fs]
+ tys <- reconstructType hsc_env False `mapM` incompletelyTypedIds
+ -- map termType `fmap` (obtainTerm hsc_env False `mapM` incompletelyTypedIds)
+
+ let substs = [computeRTTIsubst ty ty'
+ | (ty, Just ty') <- zip (map idType incompletelyTypedIds) tys]
+ ic' = foldr (flip substInteractiveContext) ic
+ (map skolemiseSubst $ catMaybes substs)
+ return hsc_env{hsc_IC=ic'}
+
+skolemiseSubst subst = subst `setTvSubstEnv`
+ mapVarEnv (fst.skolemiseTy) (getTvSubstEnv subst)
+