On Oct 28, 2005, at 2:54 PM, Jonathan Scott Duff wrote:
On Fri, Oct 28, 2005 at 02:29:36PM -0400, Stevan Little wrote:
I should be allowed to create a role with all sorts of conflicts which
I leave for the classes to deal with.

Er, why? I've read this sentence several times and I'm really having
trouble grasping why anyone would deliberately create a conflicted role
and want to postpone the conflict resolution until later.

Well, certain classes might want to deal with the conflict in certain ways.

role Foo {
    method foo { [ 1, 2, 3 ] }
}

role Bar {
    method foo { { one => 1, two => 2, three => 3 } }
}

role FooBar {
    does Foo; does Bar;
    method display_foo {
        self.foo.values.join(', ');
    }
}

class MyFooArray does FooBar {
    &foo := &Foo::foo;
}

class MyFooHash does FooBar {
    &foo := &Bar::foo;
}

The conflict here basically allows the user of FooBar to determine what kind of data structure to use, while also providing basic means of displaying the data structure. The example a little contrived, but it might be a useful technique in some areas.

It seems to me
that conflicts should be resolved sooner rather than later. Especially
in the light of run-time composition:

role A { method foo { ... } ... }
role B { method foo { ... } ... }
role C does B does A { ... }
my Dog $spot;
...
$spot does C;

Well why should this be any less dangerous that this:

    my $spot = (class { does A; does B; }).new();

Which is what it will be desugared into anyway.

It might also be possible for the compiler to catch this kind of stuff too.

Would you rather wait until perl is actually executing that last line
of code before finding out there's a conflict or would you rather know
there's a conflict at compile-time (when C is immediately composed of
A and B)?

To be totally honest, I think if you do runtime role composition with a role which you know has a conflict (I mean I assume you either created that role, or know what it provides before you use it), then you deserve all the pain and suffering associated with it.

Yes, I realize that Perl6 already has the "problem" that run-time
composition could cause conflicts, but I want to have a slightly
smaller chance of running into it :)

Actually, according to the "for entertainment purposes only" A12, if I do this:

    $spot does Dog does Cat;

I am really doing this:

    $spot = (class { is (class { does Dog; }); does Cat; }).new();

So it won't actually conflict.

Stevan



Reply via email to