-
Notifications
You must be signed in to change notification settings - Fork 179
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
Alternative to keysSet that uses Arg to keep the value #814
Comments
It's safe enough. It could be defeated by overlapping instances, but that won't cause a memory safety problem. I really like this idea. Could you write the libraries mailing list to see if anyone has suggested improvements to the proposed API? |
What about going the other way, by the way? And should we have unsafe versions that let the user provide the conversion function? |
Sure, I'll do this tonight.
You can already go the other way with the existing public API, like this: |
How does that go the other way? |
I'm not sure exactly what you mean here. What's the type of the functions you're asking for? |
The thing I originally proposed has type |
Oh, I see now. Sleepy, so got confused. What I meant about an unsafe version was unsafeToSet :: (k -> a -> b) -> Map k a -> Set b
unsafeToMap :: (b -> (k, a)) -> Set b -> Map k a Probably not by those names though. |
(The unsafe things could also live in an |
Sure, but note that those would also just be convenience functions that can be implemented in terms of the public API: unsafeToSet f = mapMonotonic (\(Arg k v) -> f k v) . mapToArgSet
unsafeToMap f = argSetToMap . mapMonotonic (uncurry Arg . f)
See also #816, which would let you do the same by using |
I wrote #817 that adds my original function plus the one that goes the other way that you asked for. I'll do the unsafe versions in a separate PR. |
This function seems safe to me, since
Arg k a
'sEq
andOrd
instances only care aboutk
and nota
. Assuming I'm right about that, would this be worth adding toData.Map
(or maybeData.Set
), as a more powerful alternative tokeysSet
?The text was updated successfully, but these errors were encountered: