From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id JAA03921 for caml-redistribution; Mon, 3 Jun 1996 09:14:55 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id BAA22242 for ; Sun, 2 Jun 1996 01:19:56 +0200 Received: from kronstadt.rahul.net (kronstadt.rahul.net [204.95.70.128]) by concorde.inria.fr (8.7.1/8.7.1) with SMTP id BAA06594 for ; Sun, 2 Jun 1996 01:19:52 +0200 (MET DST) Received: (from itz@localhost) by kronstadt.rahul.net (8.6.12/8.6.12) id QAA00493; Sat, 1 Jun 1996 16:19:02 -0700 Date: Sat, 1 Jun 1996 16:19:02 -0700 Message-Id: <199606012319.QAA00493@kronstadt.rahul.net> From: Ian T Zimmerman To: caml-list@pauillac.inria.fr Subject: ocaml, inheritance vs. subtyping? Sender: weis Hi, I am just starting with ocaml, so please have mercy on a newbie :-) I am somewhat perplexed by the passage in the manual on virtual methods (pp. 29-30). Let's start with the first paragraph on p.30: it says that int_comparable2 is not a subtype of int_comparable, even though the former inherits from the latter! Now for a person with an experience in a non-functional OO language (C++ or Eiffel or Sather) it seems _very strange_ that the subtype and inheritance (derivation) relations aren't the same. It even seems that not having such an overlap defeats the purpose of having OO features in the first place. How is the programmer to predict where a subtype relation actually exists? Now the manual goes on to say that this occurs because `the self type appears in contravariant position in the type of method leq'. First, am I right in decoding this as `the types of the argument of int_comparable#leq and int_comparable2#leq are in covariant relation, but they would have to be in contravariant relation for a subtyping relation to exist between int_comparable and int_comparable2'? Second, and this may be the heart of the issue, _WHY_ is type 'a -> bool inferred for leq, and not < x: unit -> int; .. > -> bool , as it surely would for a global function? If these are stupid questions, I apologize again. Maybe it's a sign that the OO features need more explanation in the manual, though. Best, -- Ian T Zimmerman +-------------------------------------------+ Box 13445 I When the dead are left to bury the dead, I Berkeley CA 94712 USA I the living remain alone. Arthur Koestler I mailto:itz@rahul.net +-------------------------------------------+