On Sat, Aug 21, 2021 at 12:50:21PM -0700, Joseph Brenner wrote: > But then, in a case like this one, how would you know in advance > that it would work, without Just Trying It: > > my @monsters = < godzilla grendel wormface blob >; > my $cool_monsters = < godzilla ghidra mothera >.Set; > > say @monsters.WHAT; # (Array) > say $cool_monsters.WHAT; # (Set) > > my $just_monsters = @monsters (-) $cool_monsters; > say $just_monsters; # Set(blob grendel wormface) > > A set difference operation seems to know what to do with arrays, > without any explicit conversion steps. I don't think you can get > that just from studying the type graphs
More likely, the set difference operation tries to coerce both of its operands into Sets, and arrays know how to make themselves into a Set (via the .Set() method inherited from List). It's much like the way the subtraction operator (&infix:<->) tries to coerce its operands into Numeric types, by asking the operands to return their "Numeric" value, or the way the concatenation operator (&infix:<~>) coerces its arguments into Stringy types. Pm