From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA17388; Tue, 25 Jun 2002 04:44:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA17587 for ; Tue, 25 Jun 2002 04:44:10 +0200 (MET DST) Received: from wetware.wetware.com (wetware.wetware.com [199.108.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5P2i9H28356 for ; Tue, 25 Jun 2002 04:44:10 +0200 (MET DST) Received: from (local broken client) localhost(dh01.wetware.com[199.108.16.41]) (2264 bytes) by wetware.wetware.com via sendmail with P:esmtp/R:bind_hosts/T:inet_zone_bind_smtp (sender: ) id for ; Mon, 24 Jun 2002 19:44:08 -0700 (PDT) (Smail-3.2.0.114 2001-Aug-6 #1 built 2002-Jan-4) Date: Mon, 24 Jun 2002 19:46:21 -0700 Mime-Version: 1.0 (Apple Message framework v482) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: [Caml-list] subtyping and inheritance (bug?) From: james woodyatt To: The Trade Content-Transfer-Encoding: 7bit Message-Id: X-Mailer: Apple Mail (2.482) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk everyone-- Consider the following variation on a theme currently found in another thread on this list: > class tree = > object (_:'self) > val v = (None : string option) > val ch = ([] : 'self list) (* NOTE: 'a list is co-variant in 'a *) > method value_get = v > method value_set x = {< v = x >} > method children_get = ch > method children_set x = {< ch = x >} > end;; > > class colortree = > object > inherit tree > method color = "evergreen" > end;; > > ((new colortree) :> tree);; (* ERROR! *) Here, the compiler (ocaml-3.04) complains that objects of class subtree cannot be coerced to class tree. Apparently, the problem is that colortree is only a subtype of tree if colortree list is a subtype of tree list, *BUT* colortree list is only a subtype of tree list if colortree is a subtype of tree, i.e. if the compiler cannot independently validate these two conditions, then the subtype relation is not inferred. My question: is this a bug? If so, is it known already, and will it be fixed? (I care about this because I'm finding that functional object style programming is a handy way to deal with problems implementing extensible state machines.) In any case, I think I'd prefer a warning when a class type cannot be used as a supertype of its descendants. The added expense of using classes instead of modules and functors is only really worth it, in my view, if you're using inheritance *and* subtyping. I'm not sure I see any real value in being able to use inheritance to produce descendant classes that are not subtypes of their ancestors. A warning, if not an error, would be better than nothing. -- j h woodyatt ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners