develooper Front page | perl.perl6.language | Postings from July 2005

Re: Messing with the type heirarchy

Thread Previous | Thread Next
Larry Wall
July 27, 2005 11:05
Re: Messing with the type heirarchy
Message ID:
On Wed, Jul 27, 2005 at 11:00:20AM +0000, Luke Palmer wrote:
: Let's say that Perl 6 does not provide a complex number class by
: default.  How would you go about writing one?  Well, let's do the
: standard Perl practice of making words that your users are supposed to
: say in their code roles.
:     role Complex { 
:         # implementation details are unimportant (as always :-p)
:     }
: Now, where does it belong in the type heirarcy so it can interact well
: with standard types?  It belongs *above* Num (and below whatever is
: above Num).  Everything that is a Num is a Complex right?

Not according to Liskov.  Num is behaving more like a constrained
subtype of Complex as soon as you admit that "isa" is about both
implementation and interface.  By the interface definition it's
slightly truer to say that Complex is a Num because it extends Num's
interface.  But this is one of the standard OO paradoxes, and we're
hoping roles are the way out of it.  (Or to be less precise and more
accurate, we're hoping it's the way to sweep the problem under N
carpets where N is greater than 0 most of the time.)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About