<p dir="ltr">+1 on the function. -1/2 on the name.</p>
<div class="gmail_quote">On Jun 27, 2016 5:45 PM, "Nicolas Godbout" <<a href="mailto:nicolas.godbout@gmail.com">nicolas.godbout@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"><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>
</blockquote></div>