HaloO,

I wrote:
And finally the combined class

  class GenLocSquare is GenSquare does GenPointMixin
  {}

I'm still pondering how one achieves method combination of the
role's and the class' methods. Here are two ideas. The first
is to use an 'is extended' part in the role that re-opens the
class when the role is composed. Question is how such a class
extension addresses the unextended class. Does the call($p) do
what I hope it does?

role GenPointMixin
{
   has Int $.x;
   has Int $.y;
   is extended
   {
      method equal( ::?CLASS GenEqual: ::?CLASS $p --> Bool )
      {
         return call($p) and self.x == $p.x and self.y == $p.y;
      }
   }
}

The second idea is to subclass an anonymous class when the
role is composed. I don't know if this is valid syntax but
the anonymous class would provide a proper superclass interface
such that the equal method can be combined from the role's
definition that goes into the anonymous class and the uncomposed
class' version of the equal method. Note that the presence of
such a method is guaranteed by the GenEqual type constraint on
the invocant type of the method.

role GenPointMixin is ::?CLASS
{
   has Int $.x;
   has Int $.y;
   method equal( ::?CLASS GenEqual: ::?CLASS $p --> Bool )
   {
       return call($p) and self.x == $p.x and self.y == $p.y;
   }
}

Regards, TSa.
--

Reply via email to