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

Henning Thielemann lemming at henning-thielemann.de
Tue Jun 28 09:19:16 UTC 2016


On Mon, 27 Jun 2016, Nicolas Godbout wrote:

> 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.

I think I'd prefer the (Map String String) variant to an obscure Set 
lookup function. I wonder whether you will later use the Map anyway, as 
the compiler grows and you need to attach more data to tokens. In order to 
make your intent clearer you might define

   newtype SharedToken = SharedToken String

and use (Map String SharedToken).


More information about the Libraries mailing list