Proposal: add 'equating' function to Data.List

Edward Kmett ekmett at gmail.com
Sat Jul 19 12:44:44 UTC 2014


I'm ever so slightly +1 on this proposal.

Why? Because it gets reinvented every 4 months, and by just adding it we can stop having this discussion.

I hereby proposed there exists a "co-Fairbairn threshold", the point at which the traffic caused by fighting against adding a commonly reinvented simple composition outweighs the pedagogical gain of pushing people to understand the simpler parts.

That said, I'd prefer it live alongside comparing, and not get pushed redundantly around to other modules.

-Edward

> On Jul 18, 2014, at 5:11 PM, Andreas Abel <abela at chalmers.se> wrote:
> 
> I am not super excited about library functions like
> 
>  comparing = (compare `on`)
>  equating  = ((==) `on`)
> 
> It is rather knowledge how to use 'on', a programming pattern.  The problem we have to solve is how we get a user searching for
> 
>  sortOn : Ord b => (a -> b) -> [a] -> [a]
> 
> to find an explanation of the simple solution
> 
>  sortOn f = sortBy (compare `on` f)
> 
> This problem of API explanation has been discussed on this list.  Maybe instead of adding such simple functions to the library, one could put out a hoogle- and hayoo-indexed package that contains all such functions that could be expected to be in the library but are not since they have trivial implementations.
> 
> Cheers,
> Andreas
> 
> P.S.: In fact, `sortOn' would be more useful than `comparing' since it at least saves two words.
> 
>> On 18.07.2014 21:31, Henning Thielemann wrote:
>> Am 18.07.2014 21:26, schrieb Frerich Raabe:
>> 
>>> In a similiar vein as with 'comparing', I think it would be nice if
>>> there was a function which encapsulates this use case, like
>>> 
>>>   equating :: Eq b => (a -> b) -> a -> a -> Bool
>>>   equating = on (==)
>>> 
>>> such that one can write
>>> 
>>>   groupBy (equating snd)
>> 
>> I think it belongs to Data.Eq.
>> 
>> I have already added it to my own Data.Eq module:
>> 
>> http://hackage.haskell.org/package/utility-ht-0.0.10/docs/Data-Eq-HT.html
>> 
>> this way I do not need to depend on a new GHC version in order to use it.
>> 
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
> 
> 
> -- 
> Andreas Abel  <><      Du bist der geliebte Mensch.
> 
> Department of Computer Science and Engineering
> Chalmers and Gothenburg University, Sweden
> 
> andreas.abel at gu.se
> http://www2.tcs.ifi.lmu.de/~abel/
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries


More information about the Libraries mailing list