Dan Sugalski wrote:
We can't devolve to isa checking under the hood, because there are
cases where a class can assert that it has a role without pulling in
the role externally. (Storable, for example, will be a likely thing
here as classes assert they do Storable without pulling in an external
Storable role, since a generic Storable's generically useless) So
there will be classes that have a role in them without having a class
of the same name in their inheritance hierarchy anywhere.
Does, though, can only check the assertions of whether a class does
the role in question--it can't check inheritance, because while Perl 6
makes roles and classes more or less the same (kinda sorta) that's not
true of other languages. If I have an Objective-C or Java object of
class Foo, and Foo implements the Bar interface, then that object
does(Bar) while not being isa(Bar), and isa(Foo) without does(Foo).
I'm not sure that this is correct. In Java if you write the following code
class Foo implements Bar
{
}
then Foo.new instanceof Bar == true
Ruby's mixins behave similarly.
Actually Ruby uses inheritance to implement mixins. running the
following code
module TestMod
end
class TestClass
include TestMod
end
creates an anomynous class that contains a reference to TestMod. This is
used as the superclass of TestClass
p TestClass.ancestors #=> [TestClass, TestMod, Object, Kernel]
--
Mark Sparshatt