Data.List.maximumBy uses counter-intuitive ordering

Henning Thielemann lemming at henning-thielemann.de
Fri Dec 28 15:37:50 UTC 2018


On Fri, 28 Dec 2018, Johannes Waldmann 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.

Btw. Data.Semigroup exports Min and Max that are both left-biased:

Prelude Data.Semigroup> min (Arg 2 3) (Arg 2 2) :: Arg Int Int
Arg 2 3
Prelude Data.Semigroup> max (Arg 2 3) (Arg 2 2) :: Arg Int Int
Arg 2 3


More information about the Libraries mailing list