HaloO,

After re-reading about the typing of mixins in
http://www.jot.fm/issues/issue_2004_11/column1
I wonder how the example would look like in Perl6.
Here is what I think it could look like:

role GenEqual
{
   method equal( : GenEqual $ --> Bool ) {...}
}

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

class GenSquare does GenEqual does GenPointMixin
{
   has Int $.side;
   method equal ( : ::?CLASS $p --> Bool )
   {
      return self.side == $p.side;
   }
}

The handwave part is the interface of the composed role to
the class it is composed into and the typing of this interface.
The article proposes to expand the mixin self type prior to the
class interface. The latter then poses type constraints onto the
class. Do roles work like that in Perl6? I mean would the approach
of the article of using two F-bounded quantifications (see the last
formular in section 8) be a valid type model for class composition?


Regards, TSa.
--

Reply via email to