Commit a4450ece authored by Joachim Breitner's avatar Joachim Breitner
Browse files

Note [Eta expansion in match]

parent 393ea739
...@@ -682,6 +682,7 @@ match renv subst (Lam x1 e1) (Lam x2 e2) ...@@ -682,6 +682,7 @@ match renv subst (Lam x1 e1) (Lam x2 e2)
-- It's important that this is *after* the let rule, -- It's important that this is *after* the let rule,
-- so that (\x.M) ~ (let y = e in \y.N) -- so that (\x.M) ~ (let y = e in \y.N)
-- does the let thing, and then gets the lam/lam rule above -- does the let thing, and then gets the lam/lam rule above
-- See Note [Eta expansion in match]
match renv subst (Lam x1 e1) e2 match renv subst (Lam x1 e1) e2
= match renv' subst e1 (App e2 (varToCoreExpr new_x)) = match renv' subst e1 (App e2 (varToCoreExpr new_x))
where where
...@@ -998,6 +999,24 @@ at all. ...@@ -998,6 +999,24 @@ at all.
That is why the 'lookupRnInScope' call in the (Var v2) case of 'match' That is why the 'lookupRnInScope' call in the (Var v2) case of 'match'
is so important. is so important.
Note [Eta expansion in match]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At a first glance, this (eta-expansion of the thing to match if the template
contains a lambda) might waste work. For example
{-# RULES "f/expand" forall n. f (\x -> foo n x) = \x -> foo n x #-}
(for a non-inlined "f = id") will turn
go n = app (f (foo n))
into
go n = app (\x -> foo n x)
and if foo had arity 1 and app calls its argument many times, are wasting work.
In practice this does not occur (or at least I could not tickle this "bug")
because CSE turns it back into
go n = let lvl = foo n in app (\x -> lvl x)
which is fine.
%************************************************************************ %************************************************************************
%* * %* *
Rule-check the program Rule-check the program
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment