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 WAA05969; Tue, 20 Aug 2002 22:46:24 +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 WAA05817 for ; Tue, 20 Aug 2002 22:46:23 +0200 (MET DST) Received: from motgate2.mot.com (motgate2.mot.com [136.182.1.10]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7KKkMP03425 for ; Tue, 20 Aug 2002 22:46:22 +0200 (MET DST) Received: [from pobox4.mot.com (pobox4.mot.com [10.64.251.243]) by motgate2.mot.com (motgate2 2.1) with ESMTP id NAA00236 for ; Tue, 20 Aug 2002 13:46:27 -0700 (MST)] Received: [from az33exm32.corp.mot.com (az33exm32.corp.mot.com [10.64.65.146]) by pobox4.mot.com (MOT-pobox4 2.0) with ESMTP id NAA01152 for ; Tue, 20 Aug 2002 13:46:20 -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 PSD1JCZC; Tue, 20 Aug 2002 13:46:18 -0700 Message-ID: <3D62AA9A.E3CC7596@motorola.com> Date: Tue, 20 Aug 2002 15:46:18 -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 Subject: [Caml-list] Re: Polymorphic methods in class objects References: <3D62A9DE.7C2B2CFA@motorola.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Ooops!! I'd a typo and I've changed it below. Thanx. Narayanan Krishnamurthy wrote: > > 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 > > m#goo () returns 3 > m#hoo () returns "2" > m#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 / > --- -- ************************************************************************** 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