Proposal: make minimumBy/maximumBy go through foldl', not foldr1

Bart Massey bart.massey at gmail.com
Thu Oct 29 18:55:59 UTC 2015


Oh, right: I missed the prime. Apologies for cluttering the discussion.

On Thu, Oct 29, 2015 at 11:31 AM Sumit Sahrawat, Maths & Computing, IIT
(BHU) <sumit.sahrawat.apm13 at iitbhu.ac.in> wrote:

> foldl1 is lazy, whereas foldl1' is strict. The primes are usually used to
> indicate strictness.
>
> On 29 October 2015 at 23:59, Bart Massey <bart.massey at gmail.com> wrote:
>
>> I'm super-confused here. It is claimed that the Haskell 98 Report
>> requires List.minimumBy and List.maximumBy to be lazy, but the sample
>> implementations given there use foldl1 (
>> https://www.haskell.org/onlinereport/list.html) and I can't find
>> anyplace in the report where that's explicitly said to be wrong. What am I
>> missing?
>>
>> On Thu, Oct 29, 2015 at 11:15 AM David Feuer <david.feuer at gmail.com>
>> wrote:
>>
>>> I think it would be very nice to offer a few folds tailored to specific
>>> strictness patterns. I'm not sure of the best interface, however.
>>> On Oct 29, 2015 2:07 PM, "Joachim Breitner" <mail at joachim-breitner.de>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> Am Donnerstag, den 29.10.2015, 17:34 +0200 schrieb Roman Cheplyaka:
>>>> > I just realized (thanks to this reddit thread[1]) that minimumBy is
>>>> now
>>>> > implemented through foldr1. Previously (before FTP), minimumBy from
>>>> Data.List
>>>> > used foldl1, while minimumBy from Data.Foldable used foldr1.
>>>> >
>>>> > I think that the way these were merged was a mistake.
>>>>
>>>> this has also been raised by Neil at
>>>> https://ghc.haskell.org/trac/ghc/ticket/10830
>>>>
>>>> Also note https://ghc.haskell.org/trac/ghc/ticket/3416 where it is
>>>> stated that the report demands minimum (and hence minimumBy) to be
>>>> lazy.
>>>>
>>>> Ignoring that argument, and that of not changing libraries light-
>>>> harted, I do think that foldl1' would be the better choice here; users
>>>> who rely on laziness here are likely in the minority and it would be
>>>> reasonable to expect them to manually use foldl1 or foldr1.
>>>>
>>>> BTW, why is there no fold' method in Foldable that leaves the
>>>> associativity (left, right, or mixed in case of a tree) to the Foldable
>>>> instance?
>>>>
>>>>
>>>> Greetings,
>>>> Joachim
>>>>
>>>> --
>>>> Joachim “nomeata” Breitner
>>>>   mail at joachim-breitner.dehttp://www.joachim-breitner.de/
>>>>   Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
>>>>   Debian Developer: nomeata at debian.org
>>>>
>>>>
>>>> _______________________________________________
>>>> Libraries mailing list
>>>> Libraries at haskell.org
>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>>
>>>> _______________________________________________
>>> Libraries mailing list
>>> Libraries at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>>
>
>
> --
> Regards
>
> Sumit Sahrawat
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20151029/e37e0e13/attachment.html>


More information about the Libraries mailing list