<p dir="ltr">+1</p>
<p dir="ltr">When I previously searched for (and failed to find) this function in order to implement an intern table, I remember trying 'lookup', 'lookupEQ' and 'find' in approximately that order, so that's my order if preference for its name.</p>
<p dir="ltr">'lookupInterned' or similar could work for me too if you want to scare off beginners although I don't see a strong need myself. Certainly a mention of interning in the haddocks would help.</p>
<div class="gmail_quot<blockquote class=" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
WHAT<br>
<br>
It is proposed to add a ‘lookup' function on 'Set' in the "containers" 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, returns the value<br>
stored in the set.<br>
<br>
WHY<br>
<br>
The point of this proposal is to facilitate program-wide data sharing. The 'lookup'<br>
function gives access to a pointer to an object already stored in a Set and equal<br>
to a given argument. The 'lookup' function is a natural extension to the current<br>
'lookupLT', 'lookupGT', 'lookupLE' and 'lookupGE' functions, with obvious semantics.<br>
<br>
Example use case: In a parser, the memory footprint can be reduced by collapsing<br>
all equal strings to a single instance of each string. To achieve this, one needs<br>
a way to get a previously seen string (internally, a pointer) equal to a newly<br>
parsed string. Amazingly, this is very difficult with the current "containers" library interface.<br>
One current option is to use a Map instead, e.g., 'Map String 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’ function on '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">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>