From 96d52fe2180e506a2453d334891dec792cf42e0d Mon Sep 17 00:00:00 2001 From: vidush Date: Wed, 18 Oct 2023 13:06:53 -0400 Subject: [PATCH] remove duplicates --- .../src/Gibbon/Passes/OptimizeADTLayout.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Passes/OptimizeADTLayout.hs b/gibbon-compiler/src/Gibbon/Passes/OptimizeADTLayout.hs index 01997f7d3..e19bce63c 100644 --- a/gibbon-compiler/src/Gibbon/Passes/OptimizeADTLayout.hs +++ b/gibbon-compiler/src/Gibbon/Passes/OptimizeADTLayout.hs @@ -642,7 +642,7 @@ genNewProducersAndRewriteProgram Nothing -> error "genNewProducersAndRewriteProgram : Program has no main expression." Just (mexp, ty) -> - let variablesAndProducers = getVariableAndProducer funName pmap venv ddefs newDataConName mexp + let variablesAndProducers = removeDuplicates $ getVariableAndProducer funName pmap venv ddefs newDataConName mexp in case variablesAndProducers of [] -> prg --error "no variable and producers found to modify" [(var, producer)] -> @@ -692,10 +692,10 @@ genNewProducersAndRewriteProgram mainExp = Just (newMainExp, ty) } _ -> error "" - x : xs -> error "more than one variable and producer not handled yet." + x : xs -> error ("more than one variable and producer not handled yet." ++ show variablesAndProducers) -- Function to find the the variable/s that have the type that's being optimized for the given function f --- Also return the producer of those variable/s +-- Also return the producer of) those variable/s -- Arguments -- Var -> Name of the function being optimized -- pmap -> variable to producer map @@ -1193,6 +1193,11 @@ deleteMany :: (Eq a) => [a] -> [a] -> [a] deleteMany [] = id -- Nothing to delete deleteMany (x : xs) = deleteMany xs . deleteOne x -- Delete one, then the rest. +removeDuplicates :: Eq a => [a] -> [a] +removeDuplicates list = case list of + [] -> [] + a:as -> a:removeDuplicates (P.filter (/=a) as) + fillminus1 :: [Int] -> [Int] -> [Int] fillminus1 lst indices = case lst of