Proposal: Make minimumBy and maximumBy go through foldl1

David Laing dave.laing.80 at gmail.com
Wed Jan 25 23:50:56 UTC 2017


Hi all,

I'm proposing that the implementations of minimumBy and maximumBy be
changed from using foldl1 to foldr1.

I found this in a GHC trac ticket[0] labelled 'Newcomer' that has more
details / discussion on that.

The points that stand out to me are:
- the Haskell report says that those methods should be implemented in terms
of foldl1 (although as instance methods of Foldable there might be some
wiggle room there)
- it helps solves a space leak (which at first glance feels like it might
be a more common problem than the options that foldl1 removes)
- from the discussion on the ticket, it seemed to be an agreeable middle
ground

As a side note: there have been a few proposals in the past to switch these
functions to use foldl', which seemed to have stalled.  I don't know what
the etiquette is around bringing up minor variations on old proposals
again, so I apologise if I've breached some kind of protocol here.

Although I guess I've already breached one protocol by pushing a  patch to
Phabricator for review without getting sign-off from the Core Libraries
Committee, so at least I'm being even handed with my clumsiness :)

Cheers,

Dave

[0] https://ghc.haskell.org/trac/ghc/ticket/10830
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20170126/94516031/attachment.html>


More information about the Libraries mailing list