[Haskell-cafe] Is there a library that has a strict version of `sum`?
parsonsmatt at gmail.com
Tue Aug 14 19:22:44 UTC 2018
`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.
On Tue, Aug 14, 2018 at 1:17 PM, Imants Cekusins <imantc at gmail.com> wrote:
> > 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:
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe