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 PAA30161; Thu, 13 Mar 2003 15:52:14 +0100 (MET) 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 PAA29584 for ; Thu, 13 Mar 2003 15:52:13 +0100 (MET) Received: from avalon.ens-lsh.fr (mailhost.ens-lsh.fr [193.51.131.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2DEq8f26116 for ; Thu, 13 Mar 2003 15:52:13 +0100 (MET) Received: from avalon.ens-lsh.fr (localhost [127.0.0.1]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id h2DFoC9G004507 for ; Thu, 13 Mar 2003 15:50:12 GMT Received: from ens-notes1.ens-lsh.fr (ens-notes1.ens-lsh.fr [10.2.1.44]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id h2DFoCto004504 for ; Thu, 13 Mar 2003 15:50:12 GMT Received: from ens-lyon.fr ([10.3.25.133]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2003031315510130:10153 ; Thu, 13 Mar 2003 15:51:01 +0100 Date: Thu, 13 Mar 2003 15:49:29 +0100 From: Damien Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] polymorphic methods Message-Id: <20030313154929.51f68b16.Damien.Pous@ens-lyon.fr> In-Reply-To: <20030313182702L.garrigue@kurims.kyoto-u.ac.jp> References: <20030313000716.3e6bb57c.Damien.Pous@ens-lyon.fr> <20030313105656R.garrigue@kurims.kyoto-u.ac.jp> <20030313100402.02e1ce82.Damien.Pous@ens-lyon.fr> <20030313182702L.garrigue@kurims.kyoto-u.ac.jp> Organization: mosthagloups X-Mailer: Sylpheed version 0.8.10claws13 (GTK+ 1.2.10; i386-debian-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 13/03/2003 15:51:01, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 13/03/2003 15:51:02, Serialize complete at 13/03/2003 15:51:02 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Spam: no; 0.00; damien:01 ens-lyon:01 caml-list:01 jacques:01 coercions:01 lablgtk:01 avoids:01 helper:01 recursion:01 retrieve:99 monomorphic:01 incompatible:01 semantically:01 quantified:01 inherit:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 13 Mar 2003 18:27:02 +0900 Jacques Garrigue wrote: > > but that's not really a beautiful piece of code ! > And I would not have expected it to be! > This was just a theoretical answer. :-) > If you are bothered by coercions, you may have a look at the trick in > lablgtk, which avoids polymorphic methods: give the parent as > argument. > let new_node ?parent () = > let n = new node in > begin match parent with None -> () > | Some (p : #a_t) -> p#add (n :> a_t) > end; > n > You can also do the trick in an initializer. That's what I planned to do, but my trees are 'dynamic', i.e. I need to move nodes across the tree, so an initializer is not sufficient ... -> I'll use some helper function, or the tricks that have been proposed > Alternatively, you might just have an interface of a_t without > the method m. This way you have no problem with recursion: > > class type a0_t = object > ... everything but add ... > end > class type a_t = object > inherit a0_t > method add : #a0_t -> unit > end But then, when I retrieve a child from its parent, it has no more add capability :-( > > I don't know what do you mean when saying > > "such a type cannot be defined", in fact, I could define this > > equivalent (I think it is...) : > > > > >#class type a_t = object > > > method m: 'a.( unit; ..> as 'a) -> unit > > >end > > This is not equivalent: the m in a_t is a polymorphic method, but not > the one in the recursion. Polymorphic and monomorphic methods are > incompatible, so you cannot pass an a_t to m. thanks for the explanation ! Now, questions : Would it be useful to accept such a type (not just for my trees) ? Would it be correct (semantically) ? You told about "a way to recurse on a quantified polymorphic method rather than on the whole object." (that does not exists), Would it be useful (and correct) ? Has someone studied this ? damien ------------------- 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