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 TAA01644; Wed, 4 Jun 2003 19:30:19 +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 TAA02064 for ; Wed, 4 Jun 2003 19:30:18 +0200 (MET DST) Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h54HUET04173 for ; Wed, 4 Jun 2003 19:30:17 +0200 (MET DST) Received: from 1969.ws (c-24-130-113-221.we.client2.attbi.com[24.130.113.221]) by attbi.com (rwcrmhc52) with SMTP id <2003060417301305200r2u53e>; Wed, 4 Jun 2003 17:30:13 +0000 Message-ID: <3EDE2CAB.4020801@1969.ws> Date: Wed, 04 Jun 2003 10:30:19 -0700 From: Karl Zilles User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030529 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Nicolas Cannasse CC: Lex Stein , caml-list@inria.fr Subject: Re: [Caml-list] polymorphic methods in objects? References: <002301c32a49$bef062b0$2413f9ca@WARP> In-Reply-To: <002301c32a49$bef062b0$2413f9ca@WARP> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; caml-list:01 cannasse:01 htmlman:01 dummy:01 ocaml:01 caml:01 nicolas:01 polymorphic:01 objects:02 mentions:02 unit:03 wrote:03 object:03 parameter:04 constraints:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Nicolas Cannasse wrote: > two ways of doing that : > > first, having a parameterized object : > > class ['a] my_object : object > method dummy_init : 'a -> unit > end > > But perhaps here you really want that any value passed to your object is ok. > So you have to use a polymorphic method, which is not bound to the class > type : > > class my_object : object > method dummy_init : 'a . 'a -> unit > end > > This way, you cannot of course store the parameter into a field of my_object > this it is not polymorphic. The stuff Nicolas mentions is covered in sections 3.9 and 3.10 of the current manual. You should probably read these sections, because use of polymorphic methods can sometimes require type constraints. http://caml.inria.fr/ocaml/htmlman/manual005.html#ss:parameterized-classes http://caml.inria.fr/ocaml/htmlman/manual005.html#ss:polymorphic-methods ------------------- 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