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

>
> Saying that A is a supertype of B is the equivelent of saying B is a 
> subtype of A.  Same relation, different direction.  In OO lingo, how 
> they say "B is a subtype of A" is that "B inherits from (is a subclass 
> of) A".
That's not true. That's how you say it in *some* Object Oriented 
languages. Inheritance is a tool which allows you to derive another 
object from another one. You like it to be a subtype though, it usually 
is rather difficult to build a sound inheritance system where it can 
break subtyping anyway (though if you implement the self-type 
specialization in the inheritance but not in the subtyping, it might 
work, but it's unlikely to be what you want to do). Thus, let's say that 
"inheritance is one way to obtain a subtype B out of a type A" (the only 
way in languages such as Java). In OCaml for instance, object types 
exist and subtyping between them. Classes are a mere way to produce 
values of these types, and to provide an inheritance mechanism (which is 
compatible with subtyping).
>
> I will note that Ocaml's row-level polymorphism allows you to invent 
> new supertypes of a given subtype as needed (a real nice feature, 
> IMHO).  But what he's asking for is fundamentally nonsensical.
You don't invent them, they exist. I can't agree to dismiss this 
suggestion without further thought. It might end up being non-sensical, 
maybe not. It merely suggests a way, to derive new values, whose type 
happen to be a supertype of the original one. Why not ? It may be 
considered to the Haskell-like "derive" feature, and such. It is just a 
way to build new values out of known one.


Arnaud Spiwack