Proposal #2659: Add sortOn and friends to Data.List
Duncan Coutts
duncan.coutts at worc.ox.ac.uk
Sun Oct 5 14:34:43 EDT 2008
On Sun, 2008-10-05 at 17:39 +0200, Twan van Laarhoven wrote:
> Hello list,
>
>
> Almost all uses of sortBy in user code use 'comparing', 'on' or a similar
> construction [1]. I think we should add a function that makes this common
> behavior more convenient:
>
> sortOn :: Ord b => (a -> b) -> [a] -> [a]
I think fewer names and more combinations is usually best unless there
is a really compelling reason. Just because things are often used in
combination doesn't mean we have to make a new name to represent that
composition. As functional programmers we are very used to using
composition, especially simple function application.
What is wrong with
sortBy (comparing fieldFoo) ?
It's not very long, it's pretty descriptive and easily generalises using
the 'on' function.
The only thing missing here is equating. I still have to define that
myself to write:
groupBy (equating fieldBar)
I know I can write
groupBy ((==) `on` fieldBar) but that just does not read so nicely.
So perhaps I should file a counter-proposal suggesting that all we need
to do is to add equating to Data.Eq. :-)
Duncan
More information about the Libraries
mailing list