-
Notifications
You must be signed in to change notification settings - Fork 100
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
Add more conversions between HashSet and HashMap #349
Comments
Much better to just raise the lower bound on |
I personally wouldn't mind this, but I'm not sure if anyone else would. If nobody complains by the time I bother to write the PR, then I'll do that instead.
That's not an option. |
Oh, right, it wasn't lawful. Yeah, that's no good at all. |
Please use #55 to discuss Regarding |
Regarding the proposed implementations for You can ask the |
@sjakobi yes, that's true, we should ask for that documentation. But it would take a special effort to make them hash to different values, with absolutely no benefit. |
I didn't know about #55. Now that I do, I removed I opened haskell-unordered-containers/hashable#242 about adding that guarantee. |
I wonder whether it would be better to add a more general purpose function like mapHashPreserving :: (k1 -> v1 -> (k2, v2)) -> HashMap k1 v1 -> HashMap k2 v2 Users could then implement the proposed functions like this: fromArgSet :: HashSet (Arg k a) -> HashMap k a
fromArgSet = mapHashPreserving (\(Arg k v) _ -> (k, v)) . toMap
argSet :: HashMap k a -> HashSet (Arg k a)
argSet = fromMap . mapHashPreserving (\k v -> (Arg k v, ())) The main advantage would be that users can use |
Aside from adding and removing an |
Wrap/unwrap (almost) any newtype. |
Okay, that makes sense then. And if we go with that, should we add this too? traverseHashPreserving :: Applicative t => (k1 -> v1 -> t (k2, v2)) -> HashMap k1 v1 -> t (HashMap k2 v2) |
Traverse all the things, I think. But now I'm doubting the newtype thing a bit. Mapping keys and mapping values separately, rewrite rules can turn the operation into a coercion. For the combined thing, that may also be possible, but if so will require tricky footwork. So is there any other application? |
People may want to use other But frankly I still don't have an idea what the original |
Rough sketch:
These are safe since
Arg x y
andx
have the same hash (in hashable 1.3.0.0 and up, hence the#if
). See also haskell/containers#814.The text was updated successfully, but these errors were encountered: