How is the default sum in ghc ~ 10 times slower than its foldl' ( stricter foldl equivalent) equivalent? And if so, why is it not implemented with foldl' ?
import Data.List > foldl' (+) 0 [1..10^7] 50000005000000 (0.39 secs, 963,528,816 bytes) > sum [1..10^7] 50000005000000 (4.13 secs, 1,695,569,176 bytes)
For completeness, foldl and foldr are also shown here.
> foldl (+) 0 [1..10^7] 50000005000000 (4.02 secs, 1,695,828,752 bytes) > foldr (+) 0 [1..10^7] 50000005000000 (3.78 secs, 1,698,386,648 bytes)
sum seems to be implemented using foldl , as their runtime is similar. Tested on ghc 7.10.2.
dimid source share