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

Damian Nadales damian.nadales at gmail.com
Tue Aug 14 15:22:00 UTC 2018


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 <vanessa.mchale at iohk.io>
wrote:

> Actually, vector has a sum function already:
> http://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector.html#v:sum
>
> 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 <vanessa.mchale at iohk.io>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180814/e48b142d/attachment.html>


More information about the Haskell-Cafe mailing list