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 EAA17810; Tue, 25 Jun 2002 04:54:43 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA17845 for ; Tue, 25 Jun 2002 04:54:42 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g5P2sfH00082 for ; Tue, 25 Jun 2002 04:54:41 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id LAA23808; Tue, 25 Jun 2002 11:54:30 +0900 (JST) To: jhw@wetware.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] subtyping and inheritance (bug?) In-Reply-To: References: X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020625115430E.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 25 Jun 2002 11:54:30 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: james woodyatt > 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. Sure. The children_set method contains a contravariant occurence of 'self. It cannot be compatible with its subclasses. You don't need to have mutable data to have variance incompatibilities. No bug, business as usual. Jacques Garrigue ------------------- 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