From: Matthijs Kooijman Date: Tue, 23 Jun 2009 12:24:26 +0000 (+0200) Subject: Do not apply eta expansion to application arguments. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=757befa0b3e9765ad3eca2990df8a790e187326c;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Do not apply eta expansion to application arguments. Doing this can introduce expressions such as: map (\x -> foo x) xs which is of course not really what we want. By limiting eta expansion in this way, we'll still get it where we really want it: At the top level. --- diff --git a/Normalize.hs b/Normalize.hs index 9aedb4b..cceefc0 100644 --- a/Normalize.hs +++ b/Normalize.hs @@ -43,13 +43,14 @@ import Pretty -- η abstraction -------------------------------- eta, etatop :: Transform +eta expr | is_fun expr && not (is_lam expr) = do eta expr | is_fun expr && not (is_lam expr) = do let arg_ty = (fst . Type.splitFunTy . CoreUtils.exprType) expr id <- mkInternalVar "param" arg_ty change (Lam id (App expr (Var id))) -- Leave all other expressions unchanged eta e = return e -etatop = notapplied ("eta", eta) +etatop = notappargs ("eta", eta) -------------------------------- -- β-reduction diff --git a/NormalizeTools.hs b/NormalizeTools.hs index 14e3fac..400bf88 100644 --- a/NormalizeTools.hs +++ b/NormalizeTools.hs @@ -146,22 +146,22 @@ subeverywhere trans (Case scrut b t alts) = do subeverywhere trans expr = return expr --- Apply the given transformation to all expressions, except for every first --- argument of an application. -notapplied :: (String, Transform) -> Transform -notapplied trans = applyboth (subnotapplied trans) trans +-- Apply the given transformation to all expressions, except for direct +-- arguments of an application +notappargs :: (String, Transform) -> Transform +notappargs trans = applyboth (subnotappargs trans) trans -- Apply the given transformation to all (direct and indirect) subexpressions --- (but not the expression itself), except for the first argument of an --- applicfirst argument of an application -subnotapplied :: (String, Transform) -> Transform -subnotapplied trans (App a b) = do - a' <- subnotapplied trans a - b' <- notapplied trans b +-- (but not the expression itself), except for direct arguments of an +-- application +subnotappargs :: (String, Transform) -> Transform +subnotappargs trans (App a b) = do + a' <- subnotappargs trans a + b' <- subnotappargs trans b return $ App a' b' -- Let subeverywhere handle all other expressions -subnotapplied trans expr = subeverywhere (notapplied trans) expr +subnotappargs trans expr = subeverywhere (notappargs trans) expr -- Runs each of the transforms repeatedly inside the State monad. dotransforms :: [Transform] -> CoreExpr -> TransformSession CoreExpr