Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'elem' is O(n) for sets :( #56

Closed
neongreen opened this issue Jul 27, 2017 · 3 comments
Closed

'elem' is O(n) for sets :( #56

neongreen opened this issue Jul 27, 2017 · 3 comments

Comments

@neongreen
Copy link
Contributor

neongreen commented Jul 27, 2017

Sets usually have O(log n) elem, but IntSet and HashSet have O(n) elem because the elem from Foldable is slower than it could be (since it can't use the Hashable or Ord constraints). Facepalm.

We can fix it by doing something like this, as David Feuer proposed at [email protected]:

class Foldable f where
  type ElemConstr t :: * -> Constraint
  type ElemConstr t = Eq

  elem :: ElemConstr t a => a -> t a -> Bool
  default elem :: (ElemConstr t ~ Eq, Eq a) => a -> t a -> Bool

(But for NontrivialContainer instead of Foldable.)

@neongreen neongreen changed the title elem is O(n) for sets :( 'elem' is O(n) for sets :( Jul 27, 2017
@dfeuer
Copy link

dfeuer commented Jul 31, 2017

@neongreen this is probably meant for the less handsome (but better at Haskell!) David Feuer @treeowl

@neongreen
Copy link
Contributor Author

@dfeuer yep, I noticed my mistake and edited the message soon after posting it.

@chshersh
Copy link
Contributor

@neongreen Unfortunately, this is not possible for universum because we have OVERLAPPABLE instance. See issue #58. So we either need to implement ToList and Container using functional dependencies or remove OVERLAPPABLE instance and add default signatures. At this moment I don't know which solution is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants