From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 8D574BBAF for ; Thu, 10 Sep 2009 14:48:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEACOSqEqCNhAB/2dsb2JhbADdQYQYBYI4 X-IronPort-AV: E=Sophos;i="4.44,364,1249250400"; d="scan'208";a="46313494" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Sep 2009 14:48:43 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id n8ACmSp8009261; Thu, 10 Sep 2009 21:48:29 +0900 (JST) Date: Thu, 10 Sep 2009 21:48:27 +0900 (JST) Message-Id: <20090910.214827.104047449.garrigue@math.nagoya-u.ac.jp> To: guillaume.yziquel@citycable.ch Cc: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic method. From: Jacques Garrigue In-Reply-To: <4AA8F16F.1040009@citycable.ch> References: <4AA191F3.5000004@yziquel.homelinux.org> <4AA8F16F.1040009@citycable.ch> X-Mailer: Mew version 6.2.51 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 syntax:01 guillaume:01 guillaume:01 ocaml:01 compiler:01 inbound:98 polymorphic:01 polymorphic:01 incompatible:01 caml-list:01 pair:01 declaration:02 objects:02 garrigue:03 There are already polymorphic methods in ocaml. The syntax for your example would be: class myobject = object method id : 'a. 'a -> 'a = fun x -> x end A "polymorphic" keyword might seem simpler, but it would be complex to handle the case where a polymorphic method type contains also class parameters: class ['a] cell (x : 'a) = object method pair : 'b. 'b -> 'a * 'b = fun y -> (x,y) end More generally, you might end up with types more polymorphic than you expected, and since differently instantiated polymorphic method types are incompatible, this would be a problem. Jacques Garrigue From: Guillaume Yziquel > When developing with objects in OCaml, I'm quite often faced with > polymorphic methods. > > Such as: > > class myobject = object > method id x = x > end > > Sometimes you have many methods that you're tinkling with, and the > compiler keeps saying to you that 'a is inbound in this class > declaration. > > I'm therefore wondering if it would be a good idea to have a keyword > 'polymorphic', and one would write > > class myobject = object > polymorphic method id x = x > end > > The polymorphic keyword would be a hint that the method is polymorphic > and that there is no need to look at the class' type parameters. > > -- > Guillaume Yziquel > http://yziquel.homelinux.org/