At 10:55 AM +0100 11/27/06, TSa wrote:
Seq and Set are *both* more specific or restricted than Bag.  So it
would make more sense to say 'role Set does Bag' (and 'role Seq does
Bag'), not 'role Bag does Set'.  For illustrative purposes, replace
"Set" with "Int" and "Bag" with "Num".  Everything that is a valid
Set|Seq is a valid Bag, but the reverse isn't true.

All this depends on what kind of subtype you are creating. My proposal
is a strict extension of the interface or internal representation. Your
proposal is going the other way of restricting multiplicity to 1. It is
clear that all operations of a Bag can be carried out with a Set if you
take the multiplicity as 1. In the end it's a matter of choice. The
coolest thing would actually be to *supertype* Bag atop of Set (see the
thread 'set operations for roles').

I was not meaning to get into implementation issues so much as just to say that all bag values are a superset of all set values.

The Set and Bag types could very well, and probably should, have disjoint implementations, just as Array and Hash should probably have disjoint implementations even though you could represent all Array values as Hash values if you wanted to, for matters of efficiency.

Note that a "value" in the aforementioned refers to the whole collection object, not an element therein.

  Bag(1,2,2,2,3,3) d_union Bag(1,2,2,4,4);
    # Bag(2,3,3,4,4) or Bag(3,3,4,4) ?
Disjoint union has a Bag of Pair as output.
See http://en.wikipedia.org/wiki/Disjoint_union
So we get Bag(1=>1, 1=>2, 1=>2, 1=>2, 1=>3, 1=>3, 2=>1, 2=>2,
2=>2, 2=>4, 2=>4). Well, or as Bag of Seq (1,1; 1,2; ... ; 2,4).

I always considered disjoint_union to mean exactly the same thing as symmetric_difference, meaning an analogy to XOR. Still, Wikipedia says they are different, and its http://en.wikipedia.org/wiki/Symmetric_difference article describes the meaning I had been attributing to both. So what I was really asking was:

  Bag(1,2,2,2,3,3) symmetric_difference Bag(1,2,2,4,4);
    # Bag(2,3,3,4,4) or Bag(3,3,4,4) ?

-- Darren Duncan

Reply via email to