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 WAA05552; Tue, 20 Aug 2002 22:43:17 +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 WAA05897 for ; Tue, 20 Aug 2002 22:43:14 +0200 (MET DST) Received: from ftpbox.mot.com (ftpbox.mot.com [129.188.136.101]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7KKhCP03392 for ; Tue, 20 Aug 2002 22:43:13 +0200 (MET DST) Received: [from pobox3.mot.com (pobox3.mot.com [10.64.251.242]) by ftpbox.mot.com (ftpbox 2.1) with ESMTP id NAA10197 for ; Tue, 20 Aug 2002 13:43:11 -0700 (MST)] Received: [from az33exm32.corp.mot.com (az33exm32.corp.mot.com [10.64.65.146]) by pobox3.mot.com (MOT-pobox3 2.0) with ESMTP id NAA20231 for ; Tue, 20 Aug 2002 13:41:09 -0700 (MST)] Received: from motorola.com (hodaka.somerset.sps.mot.com [163.12.105.57]) by az33exm32.corp.mot.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2654.52) id PSD1JCYN; Tue, 20 Aug 2002 13:43:10 -0700 Message-ID: <3D62A9DE.7C2B2CFA@motorola.com> Date: Tue, 20 Aug 2002 15:43:10 -0500 From: Narayanan Krishnamurthy Organization: Motorola Somerset PowerPC Design Center X-Mailer: Mozilla 4.7 [en] (X11; U; SunOS 5.8 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr CC: nari@ibmoto.com Subject: [Caml-list] Polymorphic methods in class objects Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, This is probably a very naive question, but I'm going to ask it anyways. I was trying to define a polymorphic method 'foo' as shown in the class below, but have not been able to compile it in Ocaml because of type unification problems. I'm not sure why this is not possible, since the compiler should be able to build a variant type automatically as the value of the expression 'foo'. Is there a fundamental reason or is it because it is against the principle of strong typing. Other than defining variant types to deal with this, is there any other solution? Any help would be greatly appreciated. Thanx. (*********************************************) 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 (* I would like to do the following *) let m = new polym polym#goo () returns 3 polym#hoo () returns "2" polym#boo () returns "2.0" (****************************************************) -- ************************************************************************** Narayanan Krishnamurthy (Nari) ASP Advanced Tools and Methodology Motorola SPS Architecture and Systems Platforms Motorola Inc. Semiconductor Products Sector 7700 W. Parmer Lane, Austin, TX 78729 Loc/MD: TX32/PL30 _ email : nari@ibmoto.com / \ email: Narayanan.Krishnamurthy@motorola.com Ph : (512) 996-4863 |O O| Fax : (512) 996-7432 ************************| I |********************************************* \ o / --- ------------------- 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