Data.List.maximumBy uses counter-intuitive ordering
Eric Mertens
emertens at gmail.com
Fri Dec 28 15:26:37 UTC 2018
Hello,
My opinion on this issue is that code should not be relying on the ordering of the choice made by maximumBy or minimumBy.
If we changed something I’d prefer to document that it is undefined what element is chosen when two are considered equal by the comparison function.
Code that relies on a particular earlier or later bias should use a function that makes it clear in the name that that’s what it’s doing. Readers should not be required to memorize the behavior of minimumBy or maximumBy in this regard to understand the code they are reading.
Best regards,
Eric
> On Dec 28, 2018, at 7:18 AM, Johannes Waldmann <johannes.waldmann at htwk-leipzig.de> wrote:
>
> Dear all,
>
> this was brought up on the GHC tracker (not by me)
>
> https://ghc.haskell.org/trac/ghc/ticket/15921
>
> and it was suggested for discussion here.
>
> my summary: Data.List.maximumBy is right-biased,
> minimumBy is left-biased, and none of this is documented.
>
> - J.W.
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
More information about the Libraries
mailing list