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 FAA09414; Wed, 4 Jun 2003 05:32:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 FAA09512 for ; Wed, 4 Jun 2003 05:32:37 +0200 (MET DST) Received: from psyche.kaba.or.jp (psyche.kaba.or.jp [202.249.19.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h543WZH22619 for ; Wed, 4 Jun 2003 05:32:35 +0200 (MET DST) Received: from mail.kaba.or.jp (cascade.kaba.or.jp [202.249.19.34]) by psyche.kaba.or.jp (Postfix) with ESMTP id C6A99229A3; Wed, 4 Jun 2003 12:32:32 +0900 (JST) Received: from WARP (dhcp01.kaba.or.jp [202.249.19.36]) by mail.kaba.or.jp (Postfix) with SMTP id A034949A6C; Wed, 4 Jun 2003 12:32:32 +0900 (JST) Message-ID: <002301c32a49$bef062b0$2413f9ca@WARP> From: "Nicolas Cannasse" To: "Lex Stein" , References: Subject: Re: [Caml-list] polymorphic methods in objects? Date: Wed, 4 Jun 2003 12:31:11 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 ocamlc:01 dummy:01 nicolas:01 null:01 dump:01 polymorphic:01 compile:02 objects:02 unbound:02 unit:03 string:03 object:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Why can't objects have polymorphic methods ? I'm trying a compile and > ocamlc gets upset because I have a method with an unbound type in its > signature (see below for ocamlc error output). > > Must methods be type paramaterized through some kind of a template > mechanism? This seems a bit limiting: the methods of an object would have > their type signature fixed across the lifetime of an object. > > method dummy_init : 'a -> unit > method dump : out_channel -> unit > method init : unit -> unit > method join : string -> unit > method null : unit -> unit > method resolv : string -> hmap option > end > The method dummy_init has type 'a -> unit where 'a is unbound 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. Nicolas Cannasse ------------------- 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