From 51fc5cb5159cf0d19db3902d6d11f168e66a37a5 Mon Sep 17 00:00:00 2001 From: bringert Date: Mon, 28 Nov 2005 22:39:53 +0000 Subject: [PATCH] Transfer compilation: Change varibles which are not used to wildcards. --- src/Transfer/SyntaxToCore.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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. --