Nathan Wiger writes:
> > Polymorphic
> > types also becomes a problem: how to say that it's okay for a variable
> > to hold a Dog *or* a Cat, because we know that both of them have a
> > "pet()" method?
> 
> Seems in order to satisfy this you'd have to have a common ancestor,
> Pet, which Dog and Cat inherited:
> 
>    my Pet $foofoo;      # Can be Dog, Cat, or anything inherited
> 
> And if you didn't want inherited classes to count, you could specify
> that as an attribute:
> 
>    my Pet $foofoo : onlybase;    # Must be a Pet, not Cat/Dog
> 
> Or ":only", ":nochildren", ":justme", or any other similar word...

I was hoping Damian would be able to suggest a Perlish way of handling
typechecking and polymorphism.  Interface polymorphism leads to a
proliferation of pointless classes.

Perhaps instead of using inheritance for this, just have "implements"
and formal interfaces.  Then associate a variable with an interface
instead of an object type.

  package Cat implements Pet;
  package Dog implements Pet;

  my Pet $foo;
  $foo->feed();

Nat

Reply via email to