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 BAA07681; Wed, 7 Jul 2004 01:44:47 +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 BAA07253 for ; Wed, 7 Jul 2004 01:44:46 +0200 (MET DST) Received: from kraid.nerim.net (smtp-103-wednesday.nerim.net [62.4.16.103]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i66NijEV011153 for ; Wed, 7 Jul 2004 01:44:45 +0200 Received: from localhost (karryall.dnsalias.org [62.4.18.180]) by kraid.nerim.net (Postfix) with ESMTP id CB74341D1C; Wed, 7 Jul 2004 01:44:42 +0200 (CEST) Date: Wed, 07 Jul 2004 01:44:43 +0200 (CEST) Message-Id: <20040707.014443.92566385.oandrieu@nerim.net> To: szegedy@t-online.de Cc: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic method problem From: Olivier Andrieu In-Reply-To: <40EAEE20.2010805@t-online.de> References: <40EAEE20.2010805@t-online.de> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40EB396D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 andrieu:01 andrieu:01 2004:99 beforehand:01 polymorphic:01 olivier:02 olivier:02 compile:02 unit:03 unit:03 object:03 object:03 defining:04 equivalent:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Christian Szegedy [Tue, 06 Jul 2004]: > Can anyone tell me, why does the following piece of > code fail to compile, and how can I achieve > equivalent effect in the most convenient way? > > class a () = > object(self) > method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> > other#f > method g = (self :> a) > end Defining a class type beforehand helps: ,---- | # class type a_t = object method f : < f : unit; ..> -> unit method g : a_t end ;; | class type a_t = | object method f : < f : unit; .. > -> unit method g : a_t end | | # class a () : a_t = object (self) | method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> | other#f | method g = (self :> a_t) | end ;; | class a : unit -> a_t `---- -- Olivier ------------------- 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