HaloO,
Hmm, no one seems to read the article! There actually is another class
GenLocSquare that combines GenSquare and GenPointMixin. With that we
get a modified version of my code as follows:
role GenEqual
{
method equal( : GenEqual $ --> Bool ) {...}
}
role GenPointMixin
{
has Int $.x;
has Int $.y;
method equal( ::?CLASS GenEqual $self: ::?CLASS $p --> Bool )
This additional GenEqual type bound on the self type is all
that is needed to get the superclass interface as described
in the article.
{
return super.equal(p) and # <-- handwave
return call($p) and # normal superclass call, but I still
# think that super.equal reads better.
self.x == $p.x and self.y == $p.y;
}
}
class GenSquare does GenEqual does GenPointMixin
class GenSquare does GenEqual
{
has Int $.side;
method equal ( : ::?CLASS $p --> Bool )
{
return self.side == $p.side;
}
}
And finally the combined class
class GenLocSquare is GenSquare does GenPointMixin
{}
I initially dropped it because I thought that roles can see
the pre-composed class somehow. But as Jonathan explained they
don't---at least not in compile-time class composition. And
for runtime composition you get the empty class for free!
Regards, TSa.
--