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

Joachim Breitner mail at joachim-breitner.de
Thu Oct 29 18:06:55 UTC 2015


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20151029/b17834a7/attachment.sig>


More information about the Libraries mailing list