> I was hoping Damian would be able to suggest a Perlish way of handling
   > typechecking and polymorphism. 

If you mean static typechecking, then it is the natural enemy of polymorphism.
Either you give up interface polymorphism (a grievous loss) or you give
up static type-checking.
   
   > Interface polymorphism leads to a proliferation of pointless classes.

Actually, it's inheritance polymorphism that proliferates pretend classes
like Pet.

   > 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();


Not bad. Though I'd suggest a pragma:

        package Cat;
        use interface 'Pet';

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


Alternatively, one might imagine an attribute C<:must> that tells a variable
that anything assigned to it must provide certain methods:

        my $foo : must(feed water play poop);

        $foo = Manager->new();          # die "Manager object can't play".

An interface then becomes an alias for a particular C<must>:

        use attr_alias Pet => qw(feed water play poop);

        my $foo : must(Pet)


Not sure which I like better. :-)

Damian

Reply via email to