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

wren romano wren at community.haskell.org
Thu Jun 30 19:26:14 UTC 2016


FWIW, as someone who often interns strings in her programs, I'd
suggest *not* naming it "intern" (or variations thereon). One issue is
the "and store it if it's not there yet" issue already mentioned. But
another —and imo more important— issue is that one of the main goals
of interning things is so that you can get a fast equality check. In
general whenever we intern things we're going to return some token,
which supports fast equality, and takes up as little memory as
possible, but which can later on be cashed in for the original
(shared) value if we actually need it. In impure languages we can use
the pointer to the object as our token, but we can't do that (without
serious grossness) in Haskell so we'd return some other token like an
integer, perhaps with a newtype wrapper to keep track of its
providence so we can avoid mixing up tokens from different intern
tables.

I already have an implementation of intern tables for ByteString in my
local libraries; it'd be trivial to extend that to intern tables for
String or Text or anything else supporting either (a) equality and
hashability, or (b) orderability. IMO, if users want an intern table
then they should ask for one, they shouldn't use some ad hoc
combination of other data types which obfuscates the true purpose.
Adding this to containers should be proposed on a separate thread, but
I'm entirely willing to do it if people actually want it

-- 
Live well,
~wren


More information about the Libraries mailing list