Haskell foldl' poor performance with (++)
问题 I have this code: import Data.List newList_bad lst = foldl\' (\\acc x -> acc ++ [x*2]) [] lst newList_good lst = foldl\' (\\acc x -> x*2 : acc) [] lst These functions return lists with each element multiplied by 2: *Main> newList_bad [1..10] [2,4,6,8,10,12,14,16,18,20] *Main> newList_good [1..10] [20,18,16,14,12,10,8,6,4,2] In ghci: *Main> sum $ newList_bad [1..15000] 225015000 (5.24 secs, 4767099960 bytes) *Main> sum $ newList_good [1..15000] 225015000 (0.03 secs, 3190716 bytes) Why newList