[Haskell-cafe] Is there a library that has a strict version of `sum`?
allbery.b at gmail.com
Tue Aug 14 20:04:27 UTC 2018
The reason is historical.
One of the original reasons for Haskell's existence was to be an open
source alternative to a commercial language intended for teaching
theoretical CS concepts, Miranda. One result of this is that the Report's
Prelude, which ghc originally stuck fairly close to until things like
Applicative-Monad and Foldable, is optimized for teaching and comprehension
rather than actual usage. In short, the Prelude wasn't so much intended for
practical use, but for a class going through it and learning how to think
in terms of FP evaluation. Take a look at the Language Report's Prelude for
more examples than just sum and product.
And then came those later changes I mentioned, and a bunch of things got
rearranged in ways that kinda ruin their original tutelary intent, without
also redesigning them for practical intent.
On Tue, Aug 14, 2018 at 3:57 PM Artem Pelenitsyn <a.pelenitsyn at gmail.com>
> thank you for this question, The discussion was thought-provoking for me.
> Going back to your original inquiry, by the way, I've just noticed this
> prelude where `sum` and `product` are strict:
> I still fail to see (in this thread also) any rationale for lazy `sum`. I
> looked at this2014 Reddit thread, and it seems that not only I am puzzled:
> There is also an opinion (from quite authoritative source, may I add)
> that `foldl` should be strict, not just `sum`:
> I wonder what does libraries committee think about all that. One way to
> find… https://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> Best, Artem
> On Tue, 14 Aug 2018 at 22:37 Bryan Richter <b at chreekat.net> wrote:
>> On 08/14/2018 02:57 PM, Damian Nadales wrote:
>> > On Tue, Aug 14, 2018 at 8:10 PM Vanessa McHale <vanessa.mchale at iohk.io
>> <mailto:vanessa.mchale at iohk.io>> wrote:
>> > Yes, that was what I was never quite clear on. What is your *actual
>> problem, in context*, not the problem you think you have because you read
>> elsewhere that foldl' is more efficient?
>> > The problem I have is that sum consumes huge amount of memory. In
>> particular I'm modeling the Chimeric ledgers described in this paper
>> https://eprint.iacr.org/2018/262.pdf. In several places I have to
>> > sum up values in different lists, and as soon as I try this with large
>> lists the memory usage blows up. So that's my concrete scenario.
>> > In view of this, I though, "I can write this replacing `sum` by `foldl'
>> (+) 0` but wouldn't be nice if this function was defined already somewhere
>> else?" That's it.
>> > Please ignore this if it is a silly question, and my apologies in
>> I think your question is not silly, and quite reasonable. I think that
>> giving more context up front, however, would have helped people understand
>> what your were actually asking. Based solely on what
>> you wrote, you might have been someone who was summing [1..10] for the
>> first time ever and looking for that hypothetical foldl/foldl' analogue,
>> like Vanessa said. :) Being specific helps.
>> Having said all that, I am also surprised that `sum [1..100000000]` blows
>> up! (But now I see others are responding with rationale for that.)
>> 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.
> 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.
brandon s allbery kf8nh
allbery.b at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe