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!