rakudo/rakudo — pull request #335 by ab5tract (2014-11-30 15:01:39+00:00)
Title: Coerce set comparator operands 'up' to the least-degraded type

This patch presents the position that comparator ops could be more
DWIM-y by always coercing their arguments up the chain of complexity.

The current behavior is to coerce Setty things to Sets. This puts Bags
and Mixes in an awkward situation, as .values become True and so only
.keys comparisons matter. The approach of having (<+) and the like be
Baggy specific versions of the operator smells overcomplicated to me.

This approach preserves the original behavior by asking our dev to
be explicit about any "downgrading" of any .values inasmuch as they are
present in the operation:

$set (<) $bag.Set

This demand to a more explicit statement is the only perceived
tradeoff*, the reward of which is that one does not need to think twice
about:

my $reference-bag = bag <1 1 1 2 2 3>;
my $random-mix = mix <1 2 2 3 3 3>;

# Existing syntax:
# Bag --> Set (<=) Mix --> Set
> $reference-bag (<=) $random-mix
True

# Coercion of least surprise:
# Bag --> Mix (<=) Mix
> $reference-bag (<=) $random-mix
False

There is another option to implement this, using multi methods and
signatures. However, this implementation is way DRY-er, and thus a
better example of code (which I take it the core settings are intended
to be.. and that's judging mainly from the looks of things!).

Notes:

*Which is also arguably a better demand to make than to ask our dev to
remember a separate-but-strange (<+))