[Haskell-cafe] Sharing on equality

Ketil Malde ketil at malde.org
Wed Dec 14 10:43:26 CET 2011


Johan Brinch <brinchj at gmail.com> writes:

> Can GHC eliminate one of two equal ByteStrings, when they are compared
> and turns out to be equal?

Not in general, there is no guarantee that a is identical to b, just
because a == b.

> Say i have a map, ByteString -> Int.

  Data.Map.Map ByteString Int

> I now do a lookup on a ByteString and if it exists, I insert this
> ByteString into a list.

> Is it possible to avoid using more memory, than used by the keys in
> the map + the list structure?

> I guess, this could be done by having lookup return the key as well,
> and then insert this key into the list, however, that's a bit ugly and
> somewhat anti-intuitive.

I think this /is/ intuitive.  (Or you could replace the key in the map,
but that will still leave duplicates in the list).

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list