1
0
forked from GitHub/gf-core

Transfer compilation: Change varibles which are not used to wildcards.

This commit is contained in:
bringert
2005-11-28 22:39:53 +00:00
parent cb6f3088b5
commit 884055566e

View File

@@ -33,6 +33,7 @@ declsToCore_ = deriveDecls
optimize :: [Decl] -> C [Decl]
optimize = removeUselessMatch
>>> removeUnusedVariables
>>> betaReduce
newState :: CState
@@ -232,7 +233,19 @@ removeUselessMatch = return . map f
isSingleFieldPattern x p = case p of
PRec [FieldPattern y _] -> x == y
_ -> False
--
-- * Change varibles which are not used to wildcards.
--
-- FIXME: extend to variables bound in case expressions.
removeUnusedVariables :: [Decl] -> C [Decl]
removeUnusedVariables = return . map f
where
f :: Tree a -> Tree a
f x = case x of
EAbs (VVar id) e | not (id `isFreeIn` e) -> EAbs VWild (f e)
EPi (VVar id) t e | not (id `isFreeIn` e) -> EPi VWild (f t) (f e)
_ -> composOp f x
--
-- * Remove simple syntactic sugar.
--