HaloO, Jonathan Lang wrote:
Would (1,2,2,3,4,4) be a Seq or a Bag?
Comma constructs a Seq, of course.
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)'.
This is not any different from '3' + '4' resulting in numeric 7. It is the operator that builds Bags from (1,2,3) and (3,1,2) and then calculates the union.
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.
But you have no problem with doing numeric stuff? E.g. (1,2,3) + (3,4) actually means +(1,2,3) + +(3,4) == 3 + 2 == 5. It is the operator that indicates Set/Bag operations. And 'Seq does Bag' comes in handy here. Actually, no set operation is performed on Seq. The Seq is just used to build a Bag. This is like there is no string concatenation for numbers, arrays etc. They are stringified first. One could also write @a (|) @b and the two arrays would be flattened to Seq and then used to build a Bag. The only drawback with Bag being the Seq supertype is that people might want @a (|) @b to mean Set(@a) (|) Set(@b). The Set enforcement could also come after the Bag union: Set(@a (|) @b). Perhaps @a (|) @b delivers the result in an Array instead of a Bag value. So in general the parens ops should not be called set ops but unordered ops because this is their core meaning. They are overloaded for Bag and Set.
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.
But that should be the numeric difference of the cardinalities of the Sets. Plain - means numeric. It's the same thing that we don't do string concatenation with + but have a stringish ~ for the task. Hence it works to say 3 ~ 4 and end up with '34'.
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 are correct. This emphasizes the need for (=).
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)?
Perhaps we need both. I've chosen (/) for it's visual similarity with (|) like || and //. We could use (/?) for the disjointness test. Or doing visual games again: (%). You see the disjoint sets in the glyph. (:) might work, too.
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.
Isn't that similar in semantics to the none junction? If you have e.g. a Set of Int (1,2,3) you can express (!)(1,2,3) as Set(*..0,4..*). But I agree that it is difficult in general. Well, (!)$x might actually create a large set of almost all currently known objects in some scope. This might just be written as * (-) $x. IOW, Set(*) means all known objects. As long as a program is not wielding large data sets complement might just work---and the complement of a large set is small, of course. Note that $a (-) $b is equivalent to $a (&) (!)$b, you have it as the union. Or did you mean $a (|) (!)$b === (!)($b (-) $a)? Hmm, how is Bag complement defined in the first place? Is it just complementing the set and goes for multiplicities of 1?
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).
Correct. Regards, TSa. --