Re: [Haskell-cafe] Is there a library that has a strict version of `sum`?

Ok, so if understood the bottom line of the answers I got from Vanessa and
Hiromi the take away seems to be: if you're prototyping then stick to the
lazy version of sum, otherwise use more advanced data structures (Vectors
or Folds).
On Tue, Aug 14, 2018 at 5:18 PM Vanessa McHale
Actually, vector has a sum function already: http://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector.html#v:s...
It's strict, and I'd guess more efficient than foldl' on lists.
On 08/14/2018 09:44 AM, Vanessa McHale wrote:
To be more explicit: unless you've actually benchmarked sum vs sum' this seems to be a premature optimization and you'd be better off just using the stock sum with a sensible data structure.
On 08/14/2018 09:40 AM, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 4:25 PM Vanessa McHale
wrote: If you'd rather import a custom prelude instead of writing `sum = foldl' (+) 0` you might want to think about how dependencies affect maintaining a package.
What's the actual problem you're trying to solve?
Just add a list of values. I was expecting such a function to be already defined somewhere else.
Personally, in terms of cognitive complexity I find `sum` less complex than `fold' (+) 0`...
On 08/14/2018 04:09 AM, Damian Nadales wrote:
I thought the answer would be easy to find on the internet, but I cannot find any package that features a strict version of `sum`.
Do you know if such a function is defined anywhere? (like a custom prelude for instance)
I know it is trivial to define, but I would prefer not to repeat myself (and somebody else).
Thanks!
_______________________________________________ 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.
_______________________________________________ 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.
--
*Vanessa McHale* Functional Compiler Engineer | Chicago, IL
Website: www.iohk.io http://iohk.io Twitter: @vamchale PGP Key ID: 4209B7B5
[image: Input Output] http://iohk.io
[image: Twitter] https://twitter.com/InputOutputHK [image: Github] https://github.com/input-output-hk [image: LinkedIn] https://www.linkedin.com/company/input-output-global
This e-mail and any file transmitted with it are confidential and intended solely for the use of the recipient(s) to whom it is addressed. Dissemination, distribution, and/or copying of the transmission by anyone other than the intended recipient(s) is prohibited. If you have received this transmission in error please notify IOHK immediately and delete it from your system. E-mail transmissions cannot be guaranteed to be secure or error free. We do not accept liability for any loss, damage, or error arising from this transmission
--
*Vanessa McHale* Functional Compiler Engineer | Chicago, IL
Website: www.iohk.io http://iohk.io Twitter: @vamchale PGP Key ID: 4209B7B5
[image: Input Output] http://iohk.io
[image: Twitter] https://twitter.com/InputOutputHK [image: Github] https://github.com/input-output-hk [image: LinkedIn] https://www.linkedin.com/company/input-output-global
This e-mail and any file transmitted with it are confidential and intended solely for the use of the recipient(s) to whom it is addressed. Dissemination, distribution, and/or copying of the transmission by anyone other than the intended recipient(s) is prohibited. If you have received this transmission in error please notify IOHK immediately and delete it from your system. E-mail transmissions cannot be guaranteed to be secure or error free. We do not accept liability for any loss, damage, or error arising from this transmission

On Tue, Aug 14, 2018 at 05:22:00PM +0200, Damian Nadales wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to the lazy version of sum, otherwise use more advanced data structures (Vectors or Folds).
I can't say I understand that bottom line. A strict sum seems like a very obvious thing to want to feature very prominently in whatever set of utilities you choose to base your system on.

On Tue, Aug 14, 2018, 19:26 Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Tue, Aug 14, 2018 at 05:22:00PM +0200, Damian Nadales wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to the lazy version of sum, otherwise use more advanced data structures (Vectors or Folds).
I can't say I understand that bottom line. A strict sum seems like a very obvious thing to want to feature very prominently in whatever set of utilities you choose to base your system on.
Any idea why Prelude does not ship a sum' version? (i.e. a strict version of sum) _______________________________________________
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.

I suspect the only reason it includes sum at all is that the Report says it
must. Otherwise, well, it's a trivial fold and you can easily select the
strictness you want by how you phrase the fold.
On Tue, Aug 14, 2018 at 1:35 PM Damian
On Tue, Aug 14, 2018, 19:26 Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to
On Tue, Aug 14, 2018 at 05:22:00PM +0200, Damian Nadales wrote: the
lazy version of sum, otherwise use more advanced data structures (Vectors or Folds).
I can't say I understand that bottom line. A strict sum seems like a very obvious thing to want to feature very prominently in whatever set of utilities you choose to base your system on.
Any idea why Prelude does not ship a sum' version? (i.e. a strict version of sum)
_______________________________________________
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.
_______________________________________________ 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.
-- brandon s allbery kf8nh allbery.b@gmail.com

On 08/14/2018 11:22 AM, Damian Nadales wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to the lazy version of sum, otherwise use more advanced data structures (Vectors or Folds).
Are you implying that lazy functions are only good for prototyping? Or is there something wrong with sum in particular? More generally, why isn't sum working for you?

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? On 08/14/2018 01:07 PM, Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to the lazy version of sum, otherwise use more advanced data structures (Vectors or Folds). Are you implying that lazy functions are only good for prototyping? Or is there something wrong with sum in particular?
More generally, why isn't sum working for you?
_______________________________________________ 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.

On Tue, Aug 14, 2018 at 01:09:36PM -0500, Vanessa McHale wrote:
Are you implying that lazy functions are only good for prototyping? Or is there something wrong with sum in particular?
More generally, why isn't sum working for you? yes, that was what i was never quite clear on. what is your *actual
On 08/14/2018 01:07 pm, bryan richter wrote: problem, in context*, not the problem you think you have because you read elsewhere that foldl' is more efficient?
OP might have been a bit speculative but come on, let's not make Damian must feel under examination! :)

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
On Tue, Aug 14, 2018 at 8:10 PM Vanessa McHale
On 08/14/2018 01:07 PM, Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to the lazy version of sum, otherwise use more advanced data structures (Vectors or Folds).
Are you implying that lazy functions are only good for prototyping? Or is there something wrong with sum in particular?
More generally, why isn't sum working for you?
_______________________________________________ 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.
_______________________________________________ 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.

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.htm...

`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.

On Tue, Aug 14, 2018 at 2:57 PM Damian Nadales
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.
There's a certain tendency for people to look for even trivial canned solutions, which to my mind misses the point of functional programming. It's trivial to build exactly what you need from the building blocks you have, so canned solutions like Prelude "sum" lead both to this kind of problem when they don't quite fit, and at the same time inappropriately encourage people to go looking for "more appropriate" canned solutions. -- brandon s allbery kf8nh allbery.b@gmail.com

Yes, writing sum' = foldl' (+) 0 in a project-specific prelude (or even a local binding) is much more maintainable than grabbing a dependency on a custom prelude. On 08/14/2018 02:25 PM, Brandon Allbery wrote:
On Tue, Aug 14, 2018 at 2:57 PM Damian Nadales
mailto:damian.nadales@gmail.com> wrote: 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.
There's a certain tendency for people to look for even trivial canned solutions, which to my mind misses the point of functional programming. It's trivial to build exactly what you need from the building blocks you have, so canned solutions like Prelude "sum" lead both to this kind of problem when they don't quite fit, and at the same time inappropriately encourage people to go looking for "more appropriate" canned solutions. -- brandon s allbery kf8nh allbery.b@gmail.com mailto:allbery.b@gmail.com

On 08/14/2018 02:57 PM, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:10 PM Vanessa McHale
mailto:vanessa.mchale@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 advance.
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.)

Damian, 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: https://github.com/serokell/universum Bryan, 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: https://www.reddit.com/r/haskell/comments/2agxcb/why_is_sum_lazy/ There is also an opinion (from quite authoritative source, may I add) that `foldl` should be strict, not just `sum`: http://www.well-typed.com/blog/90/ 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 wrote:
On 08/14/2018 02:57 PM, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:10 PM Vanessa McHale
mailto:vanessa.mchale@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
sum up values in different lists, and as soon as I try this with large
particular I'm modeling the Chimeric ledgers described in this paper https://eprint.iacr.org/2018/262.pdf. In several places I have to 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
advance.
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: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Thank you all for your answers, and my apologies for not framing the
question properly.
On Tue, Aug 14, 2018 at 9:57 PM Artem Pelenitsyn
Damian,
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: https://github.com/serokell/universum
Great! Thanks ( https://www.stackage.org/haddock/lts-12.6/universum-1.2.0/Universum-Containe... ).
Bryan,
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: https://www.reddit.com/r/haskell/comments/2agxcb/why_is_sum_lazy/
There is also an opinion (from quite authoritative source, may I add) that `foldl` should be strict, not just `sum`: http://www.well-typed.com/blog/90/
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 wrote:
On 08/14/2018 02:57 PM, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:10 PM Vanessa McHale
mailto:vanessa.mchale@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
sum up values in different lists, and as soon as I try this with large
particular I'm modeling the Chimeric ledgers described in this paper https://eprint.iacr.org/2018/262.pdf. In several places I have to 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
advance.
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: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe 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: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

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
Damian,
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: https://github.com/serokell/universum
Bryan,
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: https://www.reddit.com/r/haskell/comments/2agxcb/why_is_sum_lazy/
There is also an opinion (from quite authoritative source, may I add) that `foldl` should be strict, not just `sum`: http://www.well-typed.com/blog/90/
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 wrote:
On 08/14/2018 02:57 PM, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:10 PM Vanessa McHale
mailto:vanessa.mchale@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
sum up values in different lists, and as soon as I try this with large
particular I'm modeling the Chimeric ledgers described in this paper https://eprint.iacr.org/2018/262.pdf. In several places I have to 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
advance.
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: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe 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: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On Tue, Aug 14, 2018 at 8:08 PM Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote:
Ok, so if understood the bottom line of the answers I got from Vanessa and Hiromi the take away seems to be: if you're prototyping then stick to the lazy version of sum, otherwise use more advanced data structures (Vectors or Folds).
Are you implying that lazy functions are only good for prototyping? Or
No. I know lazy functions can be quite useful.
is there something wrong with sum in particular?
From the point of view of somebody that is not that bright, like myself, it seems. Why would you need to build a huge thunk containing the representation of a sum of values. It is not that you can pattern match on integers or consume the sum incrementally.
I apologize if I infuriate people, but I really don't get the usefulness of a lazy sum function.
More generally, why isn't sum working for you?
Because if I want to test my function with 100000000 values it consumes a lot of memory.
_______________________________________________ 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.

On Tue, Aug 14, 2018 at 08:50:01PM +0200, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:08 PM Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote: is there something wrong with sum in particular?
From the point of view of somebody that is not that bright, like myself, it seems. Why would you need to build a huge thunk containing the representation of a sum of values. It is not that you can pattern match on integers or consume the sum incrementally.
I apologize if I infuriate people, but I really don't get the usefulness of a lazy sum function.
More generally, why isn't sum working for you?
Because if I want to test my function with 100000000 values it consumes a lot of memory.
Your rationale seems utterly reasonable and I'm surprised that you've even been asked to provide it. Everyone knows the problems with lazy sum. I'm actually astonished (and sorry) about the pushback you've received here. Having easy access to a sum function that doesn't blow up and *not* having easy access to one that does seem self evidently worthwhile. Tom

On Wed, Aug 15, 2018 at 8:40 AM Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Tue, Aug 14, 2018 at 08:50:01PM +0200, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:08 PM Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote: is there something wrong with sum in particular?
From the point of view of somebody that is not that bright, like myself, it seems. Why would you need to build a huge thunk containing the representation of a sum of values. It is not that you can pattern match on integers or consume the sum incrementally.
I apologize if I infuriate people, but I really don't get the usefulness of a lazy sum function.
More generally, why isn't sum working for you?
Because if I want to test my function with 100000000 values it consumes a lot of memory.
Your rationale seems utterly reasonable and I'm surprised that you've even been asked to provide it. Everyone knows the problems with lazy sum. I'm actually astonished (and sorry) about the pushback you've received here. Having easy access to a sum function that doesn't blow up and *not* having easy access to one that does seem self evidently worthwhile.
Tom _______________________________________________ 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.
+1, I agree with this wholeheartedly.

+1, I would even think strict sum should be the default
On Wed, Aug 15, 2018, 8:08 AM Michael Snoyman
On Wed, Aug 15, 2018 at 8:40 AM Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Tue, Aug 14, 2018 at 08:50:01PM +0200, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:08 PM Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote: is there something wrong with sum in particular?
From the point of view of somebody that is not that bright, like myself, it seems. Why would you need to build a huge thunk containing the representation of a sum of values. It is not that you can pattern match on integers or consume the sum incrementally.
I apologize if I infuriate people, but I really don't get the usefulness of a lazy sum function.
More generally, why isn't sum working for you?
Because if I want to test my function with 100000000 values it consumes a lot of memory.
Your rationale seems utterly reasonable and I'm surprised that you've even been asked to provide it. Everyone knows the problems with lazy sum. I'm actually astonished (and sorry) about the pushback you've received here. Having easy access to a sum function that doesn't blow up and *not* having easy access to one that does seem self evidently worthwhile.
Tom _______________________________________________ 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.
+1, I agree with this wholeheartedly. _______________________________________________ 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.

Another important data point:
When default optimization is enabled, GHC recognizes that the sum
should be strict.
That, together with the historical context explained by Brandon, is
the reason why the definition of sum has not changed. It has been
discussed numerous times on this list and in various other forums in
the community over the years.
Regards,
Yitz
On Thu, Aug 16, 2018 at 6:46 PM, André Popovitch
+1, I would even think strict sum should be the default
On Wed, Aug 15, 2018, 8:08 AM Michael Snoyman
wrote: On Wed, Aug 15, 2018 at 8:40 AM Tom Ellis
wrote: On Tue, Aug 14, 2018 at 08:50:01PM +0200, Damian Nadales wrote:
On Tue, Aug 14, 2018 at 8:08 PM Bryan Richter wrote:
On 08/14/2018 11:22 AM, Damian Nadales wrote: is there something wrong with sum in particular?
From the point of view of somebody that is not that bright, like myself, it seems. Why would you need to build a huge thunk containing the representation of a sum of values. It is not that you can pattern match on integers or consume the sum incrementally.
I apologize if I infuriate people, but I really don't get the usefulness of a lazy sum function.
More generally, why isn't sum working for you?
Because if I want to test my function with 100000000 values it consumes a lot of memory.
Your rationale seems utterly reasonable and I'm surprised that you've even been asked to provide it. Everyone knows the problems with lazy sum. I'm actually astonished (and sorry) about the pushback you've received here. Having easy access to a sum function that doesn't blow up and *not* having easy access to one that does seem self evidently worthwhile.
Tom _______________________________________________ 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.
+1, I agree with this wholeheartedly. _______________________________________________ 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.
_______________________________________________ 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.
participants (13)
-
André Popovitch
-
Artem Pelenitsyn
-
Brandon Allbery
-
Bryan Richter
-
Damian
-
Damian Nadales
-
Francesco Ariis
-
Imants Cekusins
-
Matt
-
Michael Snoyman
-
Tom Ellis
-
Vanessa McHale
-
Yitzchak Gale