<p dir="ltr">I don't think all the other xxxWith functions currently make this guarantee! I think they should, though.</p>
<div class="gmail_quote">On Jun 29, 2016 5:17 AM, "Edward Kmett" <<a href="mailto:ekmett@gmail.com">ekmett@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As another color for the bikeshed: <font face="monospace, monospace">lookupWithKey</font> would match the existing vocabulary of <font face="monospace, monospace">insertWithKey</font>, etc. <div><br></div><div>We could further document the rest of them to include the assertion that the copy of the key they give back to the combinator is the one found in the Map/Set and not the one given. Then this is just the continuation of an existing pattern in the library.<div><div><br></div><div>-Edward</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 29, 2016 at 4:18 AM, Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
good point. How about<br>
<br>
    lookupKey :: Ord a => a -> Set a -> Maybe a<br>
<br>
and<br>
<br>
    lookupKey :: Ord a => k -> Map k v -> Maybe (k, v)<br>
<br>
<br>
It might be a bit strange to talk about key in the context of Sets, but<br>
less so to someone who knows about sharing and pointers etc, and the<br>
naming convention works well for maps. There, looking up the key is<br>
likely the main purpose of the function; that we return the value along<br>
with it is a nice bonus.<br>
<br>
Greetings,<br>
Joachim<br>
<div><div><br>
Am Mittwoch, den 29.06.2016, 02:12 -0400 schrieb David Feuer:<br>
> Would we also want something similar for `Data.Map`, looking up a key<br>
> and returning the copy of the key found in the map along with the<br>
> associated value?<br>
><br>
> lookupWithInternedKeyOrWhatever :: Ord k => k -> Map k v -> (k, v)<br>
><br>
> If so, it might pay to think about a naming scheme that will make<br>
> sense for both Data.Map and Data.Set.<br>
><br>
> On Tue, Jun 28, 2016 at 12:38 PM, David Turner<br>
> <<a href="mailto:dct25-561bs@mythic-beasts.com" target="_blank">dct25-561bs@mythic-beasts.com</a>> wrote:<br>
> > +1<br>
> ><br>
> > When I previously searched for (and failed to find) this function<br>
> > in order<br>
> > to implement an intern table, I remember trying 'lookup',<br>
> > 'lookupEQ' and<br>
> > 'find' in approximately that order, so that's my order if<br>
> > preference for its<br>
> > name.<br>
> ><br>
> > 'lookupInterned' or similar could work for me too if you want to<br>
> > scare off<br>
> > beginners although I don't see a strong need myself. Certainly a<br>
> > mention of<br>
> > interning in the haddocks would help.<br>
> ><br>
> ><br>
> > WHAT<br>
> ><br>
> > It is proposed to add a ‘lookup' function on 'Set' in the<br>
> > "containers"<br>
> > package. Feedback during the next two weeks is welcome.<br>
> ><br>
> > The function<br>
> ><br>
> > > lookup :: Ord a => a -> Set a -> Maybe a<br>
> ><br>
> > is almost indentical to the 'member' function but, in addition,<br>
> > returns the<br>
> > value<br>
> > stored in the set.<br>
> ><br>
> > WHY<br>
> ><br>
> > The point of this proposal is to facilitate program-wide data<br>
> > sharing. The<br>
> > 'lookup'<br>
> > function gives access to a pointer to an object already stored in a<br>
> > Set and<br>
> > equal<br>
> > to a given argument. The 'lookup' function is a natural extension<br>
> > to the<br>
> > current<br>
> > 'lookupLT', 'lookupGT', 'lookupLE' and 'lookupGE' functions, with<br>
> > obvious<br>
> > semantics.<br>
> ><br>
> > Example use case: In a parser, the memory footprint can be reduced<br>
> > by<br>
> > collapsing<br>
> > all equal strings to a single instance of each string. To achieve<br>
> > this, one<br>
> > needs<br>
> > a way to get a previously seen string (internally, a pointer) equal<br>
> > to a<br>
> > newly<br>
> > parsed string. Amazingly, this is very difficult with the current<br>
> > "containers" library interface.<br>
> > One current option is to use a Map instead, e.g., 'Map String<br>
> > String'<br>
> > which stores twice as many pointers as necessary.<br>
> ><br>
> > HOW<br>
> ><br>
> > The git pull request at<br>
> > <a href="https://github.com/haskell/containers/pull/291" rel="noreferrer" target="_blank">https://github.com/haskell/containers/pull/291</a><br>
> > contains the straight-forward implementation of the 'lookup’<br>
> > function on<br>
> > 'Set', with test cases,<br>
> > as a patch against the current containers master branch.<br>
> ><br>
> ><br>
> > Salutations,<br>
> > Nicolas.<br>
> ><br>
> > _______________________________________________<br>
> > Libraries mailing list<br>
> > <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
> ><br>
> > _______________________________________________<br>
> > Libraries mailing list<br>
> > <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
> ><br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</div></div><div><div>--<br>
<br>
Joachim “nomeata” Breitner<br>
  <a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a> • <a href="https://www.joachim-breitner.de/" rel="noreferrer" target="_blank">https://www.joachim-breitner.de/</a><br>
  XMPP: <a href="mailto:nomeata@joachim-breitner.de" target="_blank">nomeata@joachim-breitner.de</a> • OpenPGP-Key: 0xF0FBF51F<br>
  Debian Developer: <a href="mailto:nomeata@debian.org" target="_blank">nomeata@debian.org</a></div></div><br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
<br></blockquote></div>