At 10:54 AM +0100 11/28/06, Ruud H.G. van Tol wrote:
> To start off with, I agree with your comment about making Set the
main type and making Bag an extension built upon that, as complex is
built upon num, etc.
I don't think that will work out. Modification of a Set is more complex
than modification of a Bag, so in that sense the Bag is the main type.
On the contrary, I would say that a Bag is more complicated than a
Set, both conceptually, and implementation-wise for many types of
implementations.
For conceptual, with a Set, you just know that a particular element
either does or does not exist in it. With a Bag, you additionally
have a count of how many times that element exists (with a more
practical Hash-like implementation), or you have an actual
multiplicity of instances (with a less practical Array-like
implementation), which is more information and more complicated.
Look at these implemented in terms of a Hash-like collection, for
example. A Set only has to maintain the list of keys, while the Bag
also has to maintain the associated count values for each. When Hash
values can be safely never defined, or ignored or dropped at any
given time, as with the Hash-like Set, there is less work to do than
if any of them are accounted for.
What I have said above is the same message regardless of whether Set
and/or Bag are immutable or mutable, though I assume that as Perl 6
already has Set being immutable, then if Bag were added, it would be
too.
-- Darren Duncan