Share isn't super cheap, but there are times when the memory saving is worth it. Note, if x is some kind of component type (say a tuple) then you add each component to the table you are building, and then look for the tuple in the table. At that point, equality on the components is just pointer equality since they have already been `shared'.