Several things are going on here: first of all, if you use (1,2,3)
as a key, Rakudo Perl 6 will consider this to be a slice of 3 keys: 1
, 2
and 3
. Since neither of these exist in the object hash, you get ((Any) (Any) (Any))
.
So you need to indicate that you want the list to be seen as single key of which you want the value. You can do this with $()
, so %sum{$(1,3,5)}
. This however does not give you the intended result. The reason behind that is the following:
> say (1,2,3).WHICH eq (1,2,3).WHICH
False
Object hashes internally key the object to its .WHICH
value. At the moment, List
s are not considered value types, so each List
has a different .WHICH
. Which makes them unfit to be used as keys in object hashes, or in other cases where they are used by default (e.g. .unique
and Set
s, Bag
s and Mix
es).
I'm actually working on making this the above eq
return True
before long: this should make it to the 2018.01 compiler release, on which also a Rakudo Star release will be based.
BTW, any time you're using object hashes and integer values, you will probably be better of using Bag
s. Alas not yet in this case either for the above reason.
You could actually make this work by using augment class List
and adding a .WHICH
method on that, but I would recommend against that as it will interfere with any future fixes.