On Tue, Oct 20, 2009 at 2:32 PM, Mark J. Reed <markjr...@gmail.com> wrote:
> On Mon, Oct 19, 2009 at 11:47 PM, Jon Lang <datawea...@gmail.com> wrote:
>> Because a method is part of a role, and ought to abide by the same
>> terms by which the role abides.  If Logging doesn't do Numeric, it
>> shouldn't have any methods in it that won't work unless it does.
>
> 100% agreed.
>
> So what the OP wants to do is declare a method that is available on
> all those invocants - and only those invocatnts - which do all of
> roles X, Y, and Z.  Granted, you can declare a new role XandYandZ that
> does X, Y, and Z, and define the method there, but that won't work on
> $foo unless you declare explicitly  '$foo does XandYandZ' .  The goal
> is to have the method show up no matter how $foo comes to do all three
> roles.
>
> This is an interesting idea.  Currently, it doesn't work because
> there's no place for such a method to live, so perhaps there could be
> a way to declare a "method space" for arbitrary combinations of roles,
> a sort of meta-role.  It's an odd duck, but it does sort of fall out
> of the multiple-dispatch semantics, which already let you base
> implementation chioce on arbitrary combinations of roles...

Well, if you could put a where clause on your invocant you could do that...

method m($invocant where { $_ ~~ X and $_ ~~ Y and $_ ~~ Z }: Int $a,
Int $b) { ... }

The STD.pm bot in #perl6 thinks where clauses on invocants are
allowed, but Rakudo currently seems to completely ignore them. I'm not
sure what the proper behaviour should be.

Matthew

Reply via email to