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 UAA23139; Fri, 23 Aug 2002 20:21:49 +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 UAA23137 for ; Fri, 23 Aug 2002 20:21:49 +0200 (MET DST) Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7NILmD19464 for ; Fri, 23 Aug 2002 20:21:48 +0200 (MET DST) Received: from mel-rta10.wanadoo.fr (193.252.19.193) by mel-rto6.wanadoo.fr (6.5.007) id 3D6246E8001677F6 for caml-list@inria.fr; Fri, 23 Aug 2002 20:21:48 +0200 Received: from debian (80.8.84.118) by mel-rta10.wanadoo.fr (6.5.007) id 3D49FFDD007E5A40 for caml-list@inria.fr; Fri, 23 Aug 2002 20:21:48 +0200 Received: from moi by debian with local (Exim 3.35 #1 (Debian)) id 17iJ4E-0000vm-00 for ; Fri, 23 Aug 2002 20:21:54 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic methods References: <3D6658D0.F18A453D@inrialpes.fr> Mail-Copy-To: never From: Remi VANICAT Date: Fri, 23 Aug 2002 20:21:54 +0200 In-Reply-To: <3D6658D0.F18A453D@inrialpes.fr> (Frederic Tronel's message of "Fri, 23 Aug 2002 17:46:24 +0200") Message-ID: <87r8gp77wd.dlv@wanadoo.fr> User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-debian-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Frederic Tronel writes: > Hello list, > > > I've just compiled the new 3.05 version (I will change for 3.06 > tomorrow), > and start playing a little bit with polymorphic methods. > But this small piece of code does not compile: > > class node = > object > val mutable t = None > method set_t: 'a. 'a -> unit = fun nt -> t <- Some nt > end > > File "essai.ml", line 4, characters 31-53: > This method has type 'a -> unit which is less general than 'b. 'b -> > unit you should look to this bug : http://caml.inria.fr/bin/caml-bugs/fixed?id=1274;page=44;user=guest (bug which had be fixed). To be more precise, the type of t can't be polymorphic, so the type of set_t can't too. look to this example : class node = object val mutable t = None method set_t: 'a. 'a -> unit = fun nt -> t <- Some nt method get_t: 'a. unit -> 'a option = fun () -> t end the one could do this : let t : int = let a = new node a #set_t 1.23 match a #get_t () with Some x -> x which is obviously wrong. you probably want : class ['a] node = object val mutable t = None method set_t: 'a -> unit = fun nt -> t <- Some nt method get_t: unit -> 'a option = fun () -> t end -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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