HaloO,

as a spin-off of the 'Set-returning .keys (was Re: Smart Matching
clarification)' thread I want to propose the addition of a Bag
type that completes the set of immutable types. It shall have the
following properties.

1) It is a multiset generalization of Set
2) It is a supertype of Set and Seq (a Set can of course be build
   from a Seq). That is 'Set does Bag' and 'Seq does Bag'. Note
   that a Seq is a ready-made Bag and if it happens to have no
   duplicates it behaves like a Set.
3) It has set operations as generalizations of the Set operations
4) It provides some Bag specific ops like (+) that return a Bag
   even when called with Sets
5) It provides the iteration interface (which in turn is applicable
   to the subtypes Set and Seq, of course)
6) %hash.values returns a Bag
7) %hash.keys returns a Set

The wording in section 'Immutable Types' in S06 concerning Set as
"Unordered Seqs that allow no duplicates" is a bit misleading because
it hints as Set being a subtype of Seq. The Mapping could be explained
as Set of Pair.

The Bag type could be implemented in a module but then we need a
way to do supertyping. The added Bag type would need to add a
multiplicity accessor that returns 1 to the Set implementation and
add lazy multiplicity counting to Seq. And I don't know how Hash::values
would be augmented to return a Bag. This Bag return type would guarantee
%h1.values === %h2.values to yield true when the two hashes happen to
return their values in different orders.

Comments?
--

Reply via email to