[Haskell-cafe] Is there a library that has a strict version of `sum`?
Matt
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.
Matt Parsons
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:
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180814/3232d7a5/attachment.html>
More information about the Haskell-Cafe
mailing list