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 HAA27759; Thu, 15 Nov 2001 07:44:00 +0100 (MET) 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 HAA27506 for ; Thu, 15 Nov 2001 07:43:49 +0100 (MET) 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.10.0) with ESMTP id fAF6hkj19450 for ; Thu, 15 Nov 2001 07:43:47 +0100 (MET) 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 PAA15366; Thu, 15 Nov 2001 15:43:35 +0900 (JST) To: william.newman@airmail.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] difficulties narrowing OO types In-Reply-To: <20011115100557Y.garrigue@kurims.kyoto-u.ac.jp> References: <20011114111708.A14071@rootless> <20011115100557Y.garrigue@kurims.kyoto-u.ac.jp> 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: <20011115154335H.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 15 Nov 2001 15:43:35 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Jacques Garrigue > Since the problem is with inheritance, and not with subtyping, there > are workarounds to define such classes. Basically the idea is to keep > the type of self as a parameter to the class. Actually, I realized after posting my previous message that it was a bit far-fetched for simple cases. If you just want to be able to list objects which have the type of the current class, then recursion on the type of self is enough and simpler. Here is the same example as before: class base ~pos ~friends = object (_ : 'a) method pos : int = pos method friends : 'a list = friends end class extended ~pos ~friends ~name = object inherit base ~pos ~friends method name : string = name end Which give types: class base : pos:int -> friends:('a list as 'b) -> object ('a) method friends : 'b method pos : int end class extended : pos:int -> friends:('a list as 'b) -> name:string -> object ('a) method friends : 'b method name : string method pos : int end And you can even coerce with semi-explicit coercions: # let e = new extended ~pos:1 ~friends:[] ~name:"e";; val e : extended = # let b = new base ~pos:2 ~friends:[(e :> base)];; val b : base = Hope this helps. Jacques Garrigue ------------------- 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