mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
Transfer: don't eta-expand overshadowed constructors.
This commit is contained in:
@@ -186,22 +186,27 @@ argumentTypes e = case e of
|
|||||||
|
|
||||||
-- | Fix up constructor patterns and applications.
|
-- | Fix up constructor patterns and applications.
|
||||||
replaceCons :: [Decl] -> C [Decl]
|
replaceCons :: [Decl] -> C [Decl]
|
||||||
replaceCons ds = mapM f ds
|
replaceCons ds = mapM (f cs) ds
|
||||||
where
|
where
|
||||||
cs = consArities ds
|
cs = consArities ds
|
||||||
isCons id = id `Map.member` cs
|
f :: DataConsInfo -> Tree a -> C (Tree a)
|
||||||
f :: Tree a -> C (Tree a)
|
f cs x = case x of
|
||||||
f t = case t of
|
|
||||||
-- get rid of the PConsTop hack
|
-- get rid of the PConsTop hack
|
||||||
PConsTop id p1 ps -> f (PCons id (p1:ps))
|
PConsTop id p1 ps -> f cs (PCons id (p1:ps))
|
||||||
-- replace patterns C where C is a constructor with (C)
|
-- replace patterns C where C is a constructor with (C)
|
||||||
PVar id | isCons id -> return $ PCons id []
|
PVar id | isCons id -> return $ PCons id []
|
||||||
|
-- don't eta-expand overshadowed constructors
|
||||||
|
EAbs (VVar id) e | isCons id ->
|
||||||
|
liftM (EAbs (VVar id)) (f (Map.delete id cs) e)
|
||||||
|
EPi (VVar id) t e | isCons id ->
|
||||||
|
liftM2 (EPi (VVar id)) (f cs t) (f (Map.delete id cs) e)
|
||||||
-- eta-expand constructors. betaReduce will remove any beta
|
-- eta-expand constructors. betaReduce will remove any beta
|
||||||
-- 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 x)
|
||||||
_ -> composOpM f t
|
_ -> composOpM (f cs) x
|
||||||
|
where isCons = (`Map.member` cs)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- * Do simple beta reductions.
|
-- * Do simple beta reductions.
|
||||||
|
|||||||
Reference in New Issue
Block a user