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 XAA07442; Tue, 20 Aug 2002 23:56:53 +0200 (MET DST) 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 XAA07609 for ; Tue, 20 Aug 2002 23:56:52 +0200 (MET DST) Received: from bastion.artisan.com (bastion.artisan.com [209.144.161.130]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7KLuoj29355 for ; Tue, 20 Aug 2002 23:56:51 +0200 (MET DST) Received: from ypmaster.artisan.com (ypmaster [172.16.2.1]) by bastion.artisan.com (8.9.2/8.9.2) with ESMTP id OAA12272; Tue, 20 Aug 2002 14:56:47 -0700 (PDT) Received: from granite.artisan.com (granite [172.16.10.97]) by ypmaster.artisan.com (8.9.2/8.9.2-arti) with ESMTP id OAA29120; Tue, 20 Aug 2002 14:56:46 -0700 (PDT) Received: (from bpr@localhost) by granite.artisan.com (8.9.2/8.9.2) id OAA05140; Tue, 20 Aug 2002 14:56:45 -0700 (PDT) X-Authentication-Warning: granite.artisan.com: bpr set sender to bpr@artisan.com using -f From: Brian Rogoff MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15714.47901.651153.447296@granite.artisan.com> Date: Tue, 20 Aug 2002 14:56:45 -0700 To: Narayanan.Krishnamurthy@motorola.com Cc: caml-list@inria.fr, nari@ibmoto.com Subject: Re: [Caml-list] Polymorphic methods in class objects References: <3D62A9DE.7C2B2CFA@motorola.com> X-Mailer: VM 7.00 under Emacs 20.7.1 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Narayanan Krishnamurthy writes: > (*********************************************) > class polym = > object(self) > val i = 0 > method private func1 j = j + 1 > method private func2 j = string_of_int j > method private func3 j = float_of_int j > method private foo polymf n = > polymf n > method goo () = > self#foo self#func1 2 > method hoo () = > self#foo self#func2 2 > method boo () = > self#foo self#func3 2 > end You need a bit of explicit typing. See Section 3.10 of the manual for OCaml 3.06. # class polym = object(self) val i = 0 method private func1 j = j + 1 method private func2 j = string_of_int j method private func3 j = float_of_int j method private foo : 'a . (int -> 'a) -> int -> 'a = fun polymf n -> polymf n method goo () = self#foo self#func1 2 method hoo () = self#foo self#func2 2 method boo () = self#foo self#func3 2 end;; class polym : object val i : int method boo : unit -> float method private foo : (int -> 'a) -> int -> 'a method private func1 : int -> int method private func2 : int -> string method private func3 : int -> float method goo : unit -> int method hoo : unit -> string end # let m = new polym;; val m : polym = # m#goo ();; - : int = 3 # m#hoo ();; - : string = "2" # m#boo ();; - : float = 2. -- Brian ------------------- 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