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 HashMap.findWithDefault #176
Add HashMap.findWithDefault #176
Conversation
No.
On Jan 22, 2018 10:01 PM, "Matt Renaud" <notifications@github.com> wrote:
This function is equivalent to lookupDefault but uses the same name that
the containers package uses Data.Map.Strict.findWithDefault
<https://hackage.haskell.org/package/containers-0.5.10.2/docs/Data-Map-Strict.html#v:findWithDefault>
.
This partially addresses #172
<#172>.
------------------------------
You can view, comment on, or merge this pull request online at:
#176
Commit Summary
- Add HashMap.findWithDefault.
File Changes
- *M* Data/HashMap/Base.hs
<https://github.com/tibbe/unordered-containers/pull/176/files#diff-0>
(17)
- *M* tests/Strictness.hs
<https://github.com/tibbe/unordered-containers/pull/176/files#diff-1>
(4)
Patch Links:
- https://github.com/tibbe/unordered-containers/pull/176.patch
- https://github.com/tibbe/unordered-containers/pull/176.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#176>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzi_YjJM6BeIXCuZXceLT4lyOgt5MHJks5tNUuXgaJpZM4Ro_i_>
.
|
There is almost no benefit to doing this, and it breaks backwards compatibility.
|
That's true, unordered-containers is not containers, but one would assume that their core APIs would be drop-in-replacement compatible. Is in the deprecation of the old function that you see as problematic, or the addition of the alias? I think its a little strong to say that it breaks backwards compatibility, the old |
Deprecation is breaking. What makes you think the containers API is
superior and should be followed? Lots of packages use different names for
similar things. Data.Sequence.fromFunction is a clone of
Data.Vector.generate, for example. I didn't like the name generate, so I
picked something else. Other times names are just different because
packages grew organically. It's not really a problem for the most part;
people go to the documentation to learn the local lingo for what they're
used to doing.
…On Jan 22, 2018 10:23 PM, "Matt Renaud" ***@***.***> wrote:
That's true, unordered-containers is not containers, but one would assume
that their core APIs would be drop-in-replacement compatible. Is in the
deprecation of the old function that you see as problematic, or the
addition of the alias?
I think its a little strong to say that it breaks backwards compatibility,
the old lookupDefault function still exists, the new one is just added
for consistency with Data.Map.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#176 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzi_erImhGWxcOKj31uSijRzXWOjGfBks5tNVDEgaJpZM4Ro_i_>
.
|
I guess in some sense since your code will now generate warnings when compiled, but not "breaking" in the sense of it not compiling anymore. In any case, I'm not attached to deprecating the old function, just thought I'd throw the idea out there :)
I make no claims on which API is superior, but
That's true, but a lot of packages aren't reasonable drop-in replacements, which would be my assumption for different "map" implementations. Unless I'm using functions specific to a certain implementation it would be nice to just change an import and have everything work. In the case of Sequence and Vector they're different enough that one wouldn't assume that the APIs are exactly the same (although consistency is nice).
That is what they have to do now, but I would argue the less "local lingo" there is the better. Imagine if every type constructor that was a functor used a different name for Predictable/consistent function naming make the experience of using a new package much smoother, and I don't think we should write-off making changes to improve consistency just because of how they got to this point. I do concede that I'm a newcomer to the Haskell ecosystem, and I'm not aware of all the history that exists or how difficult it is to deprecate something and make migration non-painful in this ecosystem. Would you be open to getting some input from others to see what their thoughts are? In the end its your decision, I'm just interested what the community thinks :) |
Is this the only function with the same purpose and a different name or
argument order or semantics? If there are just one or two, I'm open to
trying to harmonize, with input from the libraries list (which you should
be subscribed to, BTW). If there are more than a very few, I'd rather let
things be.
…On Jan 22, 2018 11:08 PM, "Matt Renaud" ***@***.***> wrote:
Deprecation is breaking.
I guess in some sense since your code will now generate warnings when
compiled, but not "breaking" in the sense of it not compiling anymore. In
any case, I'm not attached to deprecating the old function, just thought
I'd throw the idea out there :)
What makes you think the containers API is superior and should be followed?
I make no claims on which API is superior, but containers does ship with
GHC and is considered a "core" package, so if one API was to be canonical I
would lean towards containers.
Lots of packages use different names for similar things.
That's true, but a lot of packages aren't reasonable drop-in replacements,
which would be my assumption for different "map" implementations. Unless
I'm using functions specific to a certain implementation it would be nice
to just change an import and have everything work.
In the case of Sequence and Vector they're different enough that one
wouldn't assume that the APIs are exactly the same (although consistency is
nice).
people go to the documentation to learn the local lingo
That is what they have to do now, but I would argue the less "local lingo"
there is the better. Imagine if every type constructor that was a functor
used a different name for fmap. I curse the Java libraries at work for
this constantly, some use map, others use then, and others use transform
which all have the type of our beloved fmap.
Predictable/consistent function naming make the experience of using a new
package much smoother, and I don't think we should write-off making changes
to improve consistency just because of how they got to this point. I do
concede that I'm a newcomer to the Haskell ecosystem, and I'm not aware of
all the history that exists or how difficult it is to deprecate something
and make migration non-painful in this ecosystem. Would you be open to
getting some input from others to see what their thoughts are? In the end
its your decision, I'm just interested what the community thinks :)
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#176 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzi_dZdPy-3rzwer0Toepm4F63oKBK4ks5tNVswgaJpZM4Ro_i_>
.
|
As far as I'm aware, this is the only one. I went through the HashSet and HashMap Haddocks and everything else looks like its aligned. I'll send out a proposal to the libraries list when I get a chance. |
Let's double check things like |
86b429b
to
83c2a3f
Compare
This function is equivalent to `lookupDefault` but uses the same name that the containers package uses (https://hackage.haskell.org/package/containers-0.5.10.2/docs/Data-Map-Strict.html#v:findWithDefault). This partially addresses haskell-unordered-containers#172.
83c2a3f
to
152f881
Compare
Circling back to this, from the libraries proposal discussion linked above is that there were no strong objections to adding this method to HashMap. I'll admit that it didn't get as much input as I had hoped. The only contentious point was how/when to deprecate the existing function due to the affect of on After I've resolved the merge conflicts can this be merged? Thanks! Edit: Reworded first paragraph a little bit. |
Hey @treeowl, I've resolved merge conflicts since I originally started this, and also opted for a "soft deprecation" via comments instead of a Let me know what I can do to move this along :) |
Reviving this thread, can we merge this in? The PVP issue still hasn't been closed, so lets go with soft (aka. comment) deprecation for now until that is resolved. |
I still hate this because I still hate the function, let alone having two names for it. I'd much rather have something like foolook :: (Hashable k, Eq k) => r -> (v -> r) -> k -> HashMap k v -> r
foolook r vr k hm = maybe r vr $ lookup k hm but whatever. |
This function is equivalent to
lookupDefault
but uses the same name that the containers package uses Data.Map.Strict.findWithDefault.This partially addresses #172.