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

Set.fromAscList and Set.fromDescList keep the first of duplicates, inconsistent with other functions #1032

Open
meooow25 opened this issue Sep 1, 2024 · 2 comments
Labels

Comments

@meooow25
Copy link
Contributor

meooow25 commented Sep 1, 2024

λ> import qualified Data.Set as S
λ> import qualified Data.Map as M
λ> import Data.Semigroup (Arg(..))
λ> M.fromList [(Arg 1 2, 2), (Arg 1 3, 3)]
fromList [(Arg 1 3,3)]
λ> M.fromAscList [(Arg 1 2, 2), (Arg 1 3, 3)]
fromList [(Arg 1 3,3)]
λ> M.fromDescList [(Arg 1 2, 2), (Arg 1 3, 3)]
fromList [(Arg 1 3,3)]
λ> S.fromList [Arg 1 2, Arg 1 3]
fromList [Arg 1 3]
λ> S.fromAscList [Arg 1 2, Arg 1 3]
fromList [Arg 1 2] -- ??
λ> S.fromDescList [Arg 1 2, Arg 1 3]
fromList [Arg 1 2] -- ??

We should change this to be consistent.

@meooow25 meooow25 added the Set label Sep 1, 2024
@meooow25
Copy link
Contributor Author

meooow25 commented Sep 1, 2024

Unlike Map, Set documentation for any of the fromList functions does not specify which element will be kept in case of duplicates. If we make it consistent, we should also mention it in the docs.

Edit: In fact Map doesn't specify which key will be kept, only the value. But I suppose it would be weird if those did not match.

Are there any advantages in keeping the behavior unspecified? ...I can't think of any.

@meooow25
Copy link
Contributor Author

meooow25 commented Oct 4, 2024

On second thought, it might be better to not document this at the moment. It is a broader issue that Set/Map does not work well with such keys: #587

I would still like to make it consistent though.

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

No branches or pull requests

1 participant