This is actually a couple of questions:
1: can you extend roles by saying: role Set is extended {}
2: if yes, does this change variables for which you said $var does Set?
In other words, is the singleton class like a closure or a first-class
class?
What follows is just some example code in case my question is vague.
--Abhijit
role Set{
method add ($elt) { $self.{$elt} = 1 }
method remove ($elt) {...}
method intersection($other where Set) {
# can I write that as: method intersection (Set $other) ?
return $self.keys.grep { exists $other{$^a} }
}
}
class Set_class does Set {}
class Collector{
has %.coins does Set; # brand new singleton class
has Set_class %.stamps; # use existing class
}
my Collector $collector .= new;
$collector.coins.add(new Coin()); #okay
$collector.stamps.add(new Stamp()); #okay
# much later during compilation
role Set is extended{ # is this: die if any collision in any class
method difference ($other where Set) {...}
}
$collector.stamps.difference(...); # okay
$collector.coins.difference(...); # Is that legal?
# In other words, is the singleton class like a closure or like a
first-class class?
Abhijit A. Mahabal http://www.cs.indiana.edu/~amahabal/