summaryrefslogtreecommitdiff
path: root/src/Transfer/SyntaxToCore.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Transfer/SyntaxToCore.hs')
-rw-r--r--src/Transfer/SyntaxToCore.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Transfer/SyntaxToCore.hs b/src/Transfer/SyntaxToCore.hs
index 43506db60..308a8a582 100644
--- a/src/Transfer/SyntaxToCore.hs
+++ b/src/Transfer/SyntaxToCore.hs
@@ -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.
--