chromatic chromatic-at-wgz.org |Perl 6| wrote:
If I tell the type system that Foo and Bar are equivalent, then they're
equivalent even if they have different internal structures and no other
relationship in an inheritance sense.
I agree. If typing is turned on, you want errors if you pass the wrong
type. You have to explicitly declare that Bar is an acceptable
substitute for Foo.
The long-winded way is something like this:
declare a coersion operator that takes Bar and returns Foo as the
outside return type, but an adapted_Foo as the inside return type.
create the adapted_Foo class that "is Foo", and references the Bar
instance,
and delegates all the methods in common to the Bar,
and gives error stubs for those missing.
--John