Proposal: Add `maxOn` and `minOn` functions to Data.Ord

Tikhon Jelvis tikhon at jelv.is
Sun May 29 06:43:34 UTC 2016


I've needed argmin and argmax a few times. In at least one of the cases I
remember, I was implementing some algorithm that was specified with argmax
in pseudocode, so those names make sense to me.

On Fri, May 27, 2016 at 1:30 PM, Daniel Díaz Casanueva <
dhelta.diaz at gmail.com> wrote:

> On Fri, May 27, 2016 at 3:02 PM, Edward Kmett <ekmett at gmail.com> wrote:
>
>> Note: in general we have chosen to supply By methods, rather than On
>> methods, because he on combinator can be used to get one in terms of the
>> other. We explicitly added sortOn because it can use a Schwartzian
>> transform to be more efficient than sortBy (comparing `on` f).
>>
>> These don't have direct analogues there, however. So that usual argument
>> against adding these sorts of methods doesn't hold up.
>>
>> One thing of note is that what you are asking for here is usually called
>> argmin and argmax. Perhaps consistency with the rest of mathematics should
>> trump consistency with sortOn.
>>
>> IIRC, We already have Arg in Data.Semigroup for use with the Min and Max
>> semigroups for this purpose, so such naming would fit.
>>
>
> I'm not particularly concerned about the names that we decide. I just used
> those names because I thought they were intuitive for the current
> community. I'm happy with any other names that make sense.
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160528/ede4f6fe/attachment.html>


More information about the Libraries mailing list