TSa wrote:
Jonathan Lang wrote:
> Note that this would mean that Seq would also have set operations.

I count this as an advantage. So one can write (1,2,3) (|) (2,2,3,4,4)
to get a result of (1,2,2,3,4,4). As long as the Seq is a Set, that is
it has no duplicates, you get Set behavior through the Bag ops:
(1,2,3) (|) (2,3,4) === (1,2,3,4); (1,2,3) (&) (2,3,4) === (2,3).

Would (1,2,2,3,4,4) be a Seq or a Bag?  IMHO, the _only_ way this
could work would be if it's a Bag: if it's a Seq, I see no way that
one could resolve '(1,2,3) ∪ (3,1,2)'.

Mind you, I'm still not sold on the idea of performing set operations
on Seqs - it may be technically feasible to do so, but it strikes me
as fundamentally unintuitive.

BTW, the set/bag operations are not yet mentioned in S03 as new
operators. Here's a list what I think they should be:

   (|) union
   (&) intersection
   (^) symmetric difference
   (/) disjoint union?
   (!) complement, this is difficult because you need the surrounding set
   (-) difference
   (+) join, returns a bag
   (*) cartesian product
  (**) powerset
  (in) membership
(!in) negated membership
   (<) proper subset
   (>) proper superset
  (<=) subset
  (>=) superset
   (=) equality, also with ===
  (!=) inequality, also with !===

Initial thought: overkill.  Several of these operations (e.g., the
Cartesian product) are obscure and only of interest to mathematicians.
This isn't a reason to exclude them; but a non-mathematician should
not be made to feel like he needs to get a math degree in order to use
sets.  (On a tangent, he also shouldn't be made to feel like he has to
learn Type Theory in order to use Perl6's type system.)

I'm still bothered by the idea that you have to wrap _every_ ASCII
representative of a set operation in parentheses - something which is
only necessary when you start applying the full range of set
operations to non-Set entities.  In particular, I want 'Set - Set' to
produce the difference of the two Sets.

Setting aside the issue of the notation to be used, there are several
concerns that I have with this:

If set operations also apply to Seq, then (=) is not the same as ===.
The former ignores the order of the terms; the latter only does so for
Sets and Bags.  In a way, this is what started the whole debate.

You mention a single "disjoint union" operator: is it supposed to be
the "disjoint union" comparison operator (i.e., it returns true if the
sets are disjoint), or the "disjoint union" composition operator
(which returns a Set of Pairs, with each element being keyed according
to the Set that it was originally in)?

Saying that "complement" is difficult is an understatement.  I suppose
you _could_ get it to work by having a 'complemented Set' would keep
track of which elements it _doesn't_ have; but this opens a can of
worms that I really don't think we want to get into (e.g., "A ∪
(!)B").  And the notion of a complement with regard to the surrounding
set is already handled by the difference operator.

A Cartesian product would return a Set (or Bag, depending on the left
term) of Pairs, keyed by the elements of the left term.

A powerset strikes me as something that you'd want to do as a 0-ary
method, rather than as an operator.

Did I forget something?

You did highlight some things - for instance, a Set of Pairs is _not_
a Hash: a Hash has a further requirement that every key must be
unique, whereas a Set of Pairs allows for duplicate keys (but not
duplicate key-value pairs; go with a Bag of Pairs for that).

--
Jonathan "Dataweaver" Lang

Reply via email to