Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Add nub family of functions #135

Open
vincenthz opened this issue Sep 29, 2016 · 3 comments
Open

Add nub family of functions #135

vincenthz opened this issue Sep 29, 2016 · 3 comments
Labels
C - collection collection stuff

Comments

@vincenthz
Copy link
Member

vincenthz commented Sep 29, 2016

nub :: Eq a => [a] -> [a]

to

nub :: Eq (Element c) => c -> c
@ndmitchell
Copy link
Contributor

Use of nub at O(n^2) is nearly always a bug. I have both ordNub and hashNub defined in various places, both of which are substantially more useful. There's pretty much nothing that is just Eq.

@mgsloan
Copy link

mgsloan commented Sep 29, 2016

I agree that nubOrd or nubHash should be used inetead, most of the time. Maybe offer this one as nubEq? Gives it less primacy.

Would this be in a typeclass? Some datatypes can implement nubEq quite efficiently, because they already use Ord or Hashable under the surface. For example, nubEq for a multi hash set could just visit each bucket and nub within the bucket.

@vincenthz vincenthz changed the title Add nub Add nub family of functions Sep 29, 2016
@vincenthz
Copy link
Member Author

@ndmitchell: Agreed. I was definitely considering the Hash variant one already, since I'm adding the hash interfaces now.

@mgsloan: yes, very likely be in a typeclass so that we can offer the family of nub function for unboxed array, boxed array, string, and list. And anything else that will come after that. probably a good idea to still provide a nubEq for some cases, and thus make it less prominent.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C - collection collection stuff
Projects
None yet
Development

No branches or pull requests

3 participants