- (vars,rhss) = unzip prs
- tyvars_here = varSetElems (main_tyvar_set `intersectVarSet` exprsSomeFreeVars isTyVar (map snd prs))
- -- See notes with tyvars_here above
-
- go env fn body = returnSmpl (emptyFloats env, fn body)
-
- mk_poly tyvars_here var
- = getUniqueSmpl `thenSmpl` \ uniq ->
- let
- poly_name = setNameUnique (idName var) uniq -- Keep same name
- poly_ty = mkForAllTys tyvars_here (idType var) -- But new type of course
- poly_id = mkLocalId poly_name poly_ty
-
+ (ids,rhss) = unzip prs
+ -- For a recursive group, it's a bit of a pain to work out the minimal
+ -- set of tyvars over which to abstract:
+ -- /\ a b c. let x = ...a... in
+ -- letrec { p = ...x...q...
+ -- q = .....p...b... } in
+ -- ...
+ -- Since 'x' is abstracted over 'a', the {p,q} group must be abstracted
+ -- over 'a' (because x is replaced by (poly_x a)) as well as 'b'.
+ -- Since it's a pain, we just use the whole set, which is always safe
+ --
+ -- If you ever want to be more selective, remember this bizarre case too:
+ -- x::a = x
+ -- Here, we must abstract 'x' over 'a'.
+ tvs_here = main_tvs
+
+ mk_poly tvs_here var
+ = do { uniq <- getUniqueSmpl
+ ; let poly_name = setNameUnique (idName var) uniq -- Keep same name
+ poly_ty = mkForAllTys tvs_here (idType var) -- But new type of course
+ poly_id = mkLocalId poly_name poly_ty
+ ; return (poly_id, mkTyApps (Var poly_id) (mkTyVarTys tvs_here)) }