
`foldr (+) 0` is going to create a bunch of thunks replacing the spine of
the list. This is desirable if the number type can take advantage of
laziness in some way (eg a `data Nat = Z | Succ Nat`), but for most cases,
the `foldl' (+) 0` implementation is preferable.
`sum' = foldl' (+) 0` would (in my opinion) be a reasonable addition to the
Prelude, or at least Data.Foldable, but no one has done the work to do that
-- if you raise an issue on the GHC Trac then it will be up for discussion
and possible inclusion.
Matt Parsons
On Tue, Aug 14, 2018 at 1:17 PM, Imants Cekusins
I have to sum up values in different lists, and as soon as I try this with large lists the memory usage blows up.
did you try splitting the list in chunks and summing those chunks?
there is this chunksOf function: http://hackage.haskell.org/package/containers-0.6.0.1/ docs/Data-Sequence.html#g:9
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.