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 OAA16962; Fri, 1 Feb 2002 14:53:15 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA17075 for caml-list@pauillac.inria.fr; Fri, 1 Feb 2002 14:53:15 +0100 (MET) 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 OAA16912 for ; Fri, 1 Feb 2002 14:34:49 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g11DYm518298; Fri, 1 Feb 2002 14:34:48 +0100 (MET) Received: (from vouillon@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA16694; Fri, 1 Feb 2002 14:34:48 +0100 (MET) Date: Fri, 1 Feb 2002 14:34:48 +0100 From: Jerome Vouillon To: Frederic Tronel Cc: caml-list@inria.fr Subject: Re: [Caml-list] Recursive classes and subtyping Message-ID: <20020201143448.A16091@pauillac.inria.fr> References: <3C5A8747.BE14426@inrialpes.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 1.0i In-Reply-To: <3C5A8747.BE14426@inrialpes.fr>; from Frederic.Tronel@inrialpes.fr on Fri, Feb 01, 2002 at 01:17:11PM +0100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, > Why is it that these classes definitions are not accepted by > the compiler : > > class a = [...] > and b = > object (this) [...] > initializer this#set_al [(c :> a)] > end > and c = [...] > > while these ones can be compiled: > > class a = [...] > class c = [...] > class b = > object (this) [...] > initializer this#set_al [(c :> a)] > end > > Where is the fundamental difference ???? In the first case, the type "a" is not fully known when the coercion "(c :> a)" is performed, as the classes are mutually recursive. The compiler handles this case as if it knew nothing about the structure of the type "a". With this assumption, the only case the compiler can be sure that the type of "c" is a subtype of "a" is when the type of "c" is "a". This is not the case, hence the error message. The reason for this overly conservative (in this case) assumption is that the result of the type inference algorithm could otherwise depend on the order in which the program is typed. If you really need mutually recursive classes, a work-around is to explicitely define the classe types before defining the classes. -- Jérôme ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr