nub

Ketil Z. Malde ketil@ii.uib.no
29 Nov 2002 13:38:19 +0100


Richard Braakman <dark@xs4all.nl> writes:

> On Thu, Nov 28, 2002 at 10:21:53PM +0000, Alistair Bayley wrote:
>> Wouldn't this have been better called "unique"? (analogous to the Unix
>> program "uniq"). I was looking for a "unique" in the GHC Data.List library a
>> few days ago, and didn't see one, so I wrote my own (not realising that was
>> what "nub" did).

BTDT.

> No, Unix uniq makes only a single pass.
> uniq = map head . group

> Hmm, but with that said, I don't think I disagree with you.  Renaming
> "nub" to "unique" makes it clear that it is similar, but not identical
> to what Unix "uniq" does.

And of course the traditional Unix idiom for "nub" is 'sort | uniq'
(or (uniq . sort) if you prefer)

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants