From eb111e7b35f6942093da2c2d499833f5eff68874 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Fri, 23 Aug 2024 14:23:51 +0100 Subject: [PATCH] keep first occurence when removing duplicates --- src/Language/Fortran/Analysis/ModGraph.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Language/Fortran/Analysis/ModGraph.hs b/src/Language/Fortran/Analysis/ModGraph.hs index 3ae18500..a3ef9d60 100644 --- a/src/Language/Fortran/Analysis/ModGraph.hs +++ b/src/Language/Fortran/Analysis/ModGraph.hs @@ -99,8 +99,13 @@ genModGraph mversion includeDirs cppOpts paths = do pure () execStateT (mapM_ iter (removeDuplicates paths)) modGraph0 +-- Remove duplicates from a list preserving the left most occurrence. removeDuplicates :: Eq a => [a] -> [a] -removeDuplicates = foldl (\ acc x -> if x `elem` acc then acc else x : acc) [] +removeDuplicates [] = [] +removeDuplicates (x:xs) = + if x `elem` xs + then x : removeDuplicates (filter (/= x) xs) + else x : removeDuplicates xs modGraphToDOT :: ModGraph -> String modGraphToDOT ModGraph { mgGraph = gr } = unlines dot