Home:ALL Converter>Improve efficiency by removing concat

Improve efficiency by removing concat

Ask Time:2015-12-13T10:15:43         Author:thehandyman

Json Formatter

I'm attempting to improve the efficiency of a particular function in my code which is taking up a large amount of the runtime. After profiling, I believe this is because of the concat within the code. How could I go about improving this code to be quicker?

chunk :: C -> [A] -> [[A]]
chunk c = go []
  where s = Set.fromList (map snd (Map.toList c))
        go :: [A] -> [A] -> [[A]]
        go l []     = [l | member l s]
        go l (x:xs) = if member l s then l : go [x] xs
                                    else go (l ++ [x]) xs

Thanks for your help!

Author:thehandyman,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34247300/improve-efficiency-by-removing-concat
yy