Proposal: Add Data.List.sortNub and sortNubBy
Neil Mitchell
ndmitchell at gmail.com
Mon Mar 12 23:16:44 EDT 2007
Hi,
http://hackage.haskell.org/trac/ghc/ticket/1218
I propose the addition of sortNub and sortNubBy.
Semantically sortNub = sort . nub
Practically, if you are doing both a sort and a nub, this can be implemented as:
sortNub = map head . group . sort
This is O(n log n) [time to sort], rather than O(n^2) [time to nub].
I have seen this around several times, often called snub. People have
also used snub to mean other things, snub itself has a meaning, and
sortNub is a more accurate name (following the concatMap tradition).
I personally have defined this function at least 25 times, I suspect
others have to. I can find 5 identical versions of it on google code
[1], and I know google code is lying because it's missing ones it
found earlier.
Thanks
Neil
[1] http://www.google.com/codesearch?hl=en&lr=&q=lang%3Ahaskell+%22map+head+.+group+.+sort%22&btnG=Search
More information about the Libraries
mailing list