nub
Richard Braakman
dark@xs4all.nl
Fri, 29 Nov 2002 02:45:13 +0200
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).
No, Unix uniq makes only a single pass.
uniq = map head . group
(A much tidier definition than the one I gave a few days ago :-)
By contrast, "nub" removes duplicate elements from the list no matter
where they are.
I think both functions are useful. If I understand it right, uniq can
evaluate its argument list lazily, while nub cannot. There's no real
need to put uniq in the standard library, though.
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.
Richard Braakman