Version française
Home     About     Download     Resources     Contact us    
Browse thread
Smells like duck-typing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Arnaud Spiwack <aspiwack@l...>
Subject: Re: [Caml-list] Smells like duck-typing
skaller wrote :
> The soundness theory is simple: methods have to be covariant,
> but mutators have to be contravariant, and since mutators
> are also method they have to be *invariant*, and invariance
> effectively means an OO  class cannot have subtypes.
>   
You got that part wrong. I means that subtypes have the same types for 
the same methods (not subtypes, exactly the same types), but it can be 
extended with extra methods (you can be slighlty looser using 
specialisation of the self-type). That's how things work.


And inheritance usually needs to enforce the same invariant condition, 
for the same reasons (since other method inside the inherited class 
could make black-box uses of the overridden method... its type cannot 
change in general). Thus that goes to "generally, all inherited values 
are subtypes" (rational is : if you need to enforce a certain subtyping 
property, it needs to be enforced internally during inheritance as well).


Arnaud Spiwack