Proposal for containers: Add 'lookup' function to Data.Set

Michael Snoyman michael at snoyman.com
Tue Jun 28 09:58:59 UTC 2016


Likewise, I'm not in favor of name proliferation. To avoid confusion, I
think it's sufficient to give a clear comments in the Haddocks explaining
why one would wish to use this function.

On Tue, Jun 28, 2016 at 12:53 PM, Andreas Abel <andreas.abel at ifi.lmu.de>
wrote:

> +1 for "lookup".
>
> On 28.06.2016 11:44, Oliver Charles wrote:
>
>> I don't really see the problem with lookup. To me, that function always
>> takes a container, an index into that container, and returns the value
>> under than index or fails. It just so happens that sets are indexed by
>> the very values the contain, but I don't find the signature confusing.
>> Sure, I might not use it very often, but it's still clear enough to me
>> what it's doing.
>>
>> Ollie
>>
>>
>> On Tue, 28 Jun 2016, 10:23 a.m. Chris Wong, <lambda.fairy at gmail.com
>> <mailto:lambda.fairy at gmail.com>> wrote:
>>
>>     Python uses "intern", so perhaps that can serve as the name.
>>
>>     (See https://docs.python.org/2/library/functions.html#intern)
>>
>>     On Tue, Jun 28, 2016 at 9:47 AM, David Feuer <david.feuer at gmail.com
>>     <mailto:david.feuer at gmail.com>> wrote:
>>      > +1 on the function. -1/2 on the name.
>>      >
>>      > On Jun 27, 2016 5:45 PM, "Nicolas Godbout"
>>     <nicolas.godbout at gmail.com <mailto:nicolas.godbout at gmail.com>>
>>
>>      > wrote:
>>      >>
>>      >>
>>      >> WHAT
>>      >>
>>      >> It is proposed to add a ‘lookup' function on 'Set' in the
>>     "containers"
>>      >> package. Feedback during the next two weeks is welcome.
>>      >>
>>      >> The function
>>      >>
>>      >> > lookup :: Ord a => a -> Set a -> Maybe a
>>      >>
>>      >> is almost indentical to the 'member' function but, in addition,
>>     returns
>>      >> the value
>>      >> stored in the set.
>>      >>
>>      >> WHY
>>      >>
>>      >> The point of this proposal is to facilitate program-wide data
>>     sharing. The
>>      >> 'lookup'
>>      >> function gives access to a pointer to an object already stored
>>     in a Set
>>      >> and equal
>>      >> to a given argument. The 'lookup' function is a natural
>>     extension to the
>>      >> current
>>      >> 'lookupLT', 'lookupGT', 'lookupLE' and 'lookupGE' functions,
>>     with obvious
>>      >> semantics.
>>      >>
>>      >> Example use case: In a parser, the memory footprint can be
>>     reduced by
>>      >> collapsing
>>      >> all equal strings to a single instance of each string. To
>>     achieve this,
>>      >> one needs
>>      >> a way to get a previously seen string (internally, a pointer)
>>     equal to a
>>      >> newly
>>      >> parsed string. Amazingly, this is very difficult with the current
>>      >> "containers" library interface.
>>      >> One current option is to use a Map instead, e.g., 'Map String
>>     String'
>>      >> which stores twice as many pointers as necessary.
>>      >>
>>      >> HOW
>>      >>
>>      >> The git pull request at
>>      >> https://github.com/haskell/containers/pull/291
>>      >> contains the straight-forward implementation of the 'lookup’
>>     function on
>>      >> 'Set', with test cases,
>>      >> as a patch against the current containers master branch.
>>      >>
>>      >>
>>      >> Salutations,
>>      >> Nicolas.
>>      >>
>>      >> _______________________________________________
>>      >> Libraries mailing list
>>      >> Libraries at haskell.org <mailto:Libraries at haskell.org>
>>      >> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>      >
>>      >
>>      > _______________________________________________
>>      > Libraries mailing list
>>      > Libraries at haskell.org <mailto:Libraries at haskell.org>
>>      > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>      >
>>
>>
>>
>>     --
>>     Chris Wong (https://lambda.xyz)
>>
>>     "I had not the vaguest idea what this meant and when I could not
>>     remember the words, my tutor threw the book at my head, which did not
>>     stimulate my intellect in any way." -- Bertrand Russell
>>     _______________________________________________
>>     Libraries mailing list
>>     Libraries at haskell.org <mailto:Libraries at haskell.org>
>>     http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>>
>
> --
> Andreas Abel  <><      Du bist der geliebte Mensch.
>
> Department of Computer Science and Engineering
> Chalmers and Gothenburg University, Sweden
>
> andreas.abel at gu.se
> http://www2.tcs.ifi.lmu.de/~abel/
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160628/683cd07d/attachment.html>


More information about the Libraries mailing list