forked from GitHub/gf-core
In transfer beta reduction optimization: reduce bottom-up instead of top-down.
This commit is contained in:
@@ -200,10 +200,7 @@ replaceCons ds = mapM f ds
|
|||||||
-- redexes produced here.
|
-- redexes produced here.
|
||||||
EVar id | isCons id -> do
|
EVar id | isCons id -> do
|
||||||
let Just n = Map.lookup id cs
|
let Just n = Map.lookup id cs
|
||||||
-- abstract n (apply t)
|
abstract n (apply t)
|
||||||
vs <- freshIdents n
|
|
||||||
let c = apply t (map EVar vs)
|
|
||||||
return $ foldr (EAbs . VVar) c vs
|
|
||||||
_ -> composOpM f t
|
_ -> composOpM f t
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -215,7 +212,10 @@ betaReduce = return . map f
|
|||||||
where
|
where
|
||||||
f :: Tree a -> Tree a
|
f :: Tree a -> Tree a
|
||||||
f t = case t of
|
f t = case t of
|
||||||
EApp (EAbs (VVar x) b) e | countFreeOccur x b == 1 -> f (subst x e b)
|
EApp e1 e2 ->
|
||||||
|
case (f e1, f e2) of
|
||||||
|
(EAbs (VVar x) b, e) | countFreeOccur x b == 1 -> f (subst x e b)
|
||||||
|
(e1',e2') -> EApp e1' e2'
|
||||||
_ -> composOp f t
|
_ -> composOp f t
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user