Skip to content

union, unionBy are not symmetrical in their arguments #56

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

Closed
sharkdp opened this issue Jan 15, 2016 · 3 comments
Closed

union, unionBy are not symmetrical in their arguments #56

sharkdp opened this issue Jan 15, 2016 · 3 comments

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Jan 15, 2016

This seems weird:

union [0, 0] [1, 1] == [0, 0, 1]

I would have expected the result to be [0, 1], but at least it should be symmetrical in both arguments. I would consider several possible fixes:

  1. Remove all duplicates (i.e. union a b == nub (a <> b))
  2. Keep the duplicates within both of the arguments (i.e. union [0, 0] [1, 1] == [0, 0, 1, 1]).
  3. Remove union and unionBy from Data.Array (given that Set is the better data structure for something like this)
  4. Document the behavior if it is intended

I would vote for 1 or 3.

@garyb
Copy link
Member

garyb commented Jan 15, 2016

It definitely seems weird, although we seem to have inherited it from Haskell where it is documented as preserving duplicates in the first list. I'd vote for 3 or 4.

@sharkdp
Copy link
Contributor Author

sharkdp commented Jan 15, 2016

although we seem to have inherited it from Haskell where it is documented as preserving duplicates in the first list

Ah, good point. The same thing applies for intersect.

@garyb
Copy link
Member

garyb commented Jan 15, 2016

I can see how this behaviour makes sense for something like (\\) but I'm not so clear why you'd want it for the "set-like" functions - maybe there is a good reason though? Maybe we should indeed ditch all of the pseudo-set functions if we can't come up with a good reason for this unusual behaviour.

sharkdp added a commit to sharkdp/purescript-arrays that referenced this issue Mar 20, 2016
@garyb garyb closed this as completed in b7aafc6 Mar 20, 2016
garyb added a commit that referenced this issue Mar 20, 2016
Update documentation, resolves #56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants