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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 3C6F1BBAF for ; Thu, 10 Sep 2009 15:09:57 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AosBAIeXqEpV2gB5mWdsb2JhbACbPwEBAQEBCAsKBxPBXYQYBYpc X-IronPort-AV: E=Sophos;i="4.44,364,1249250400"; d="scan'208";a="35814512" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail1-smtp-roc.national.inria.fr with SMTP; 10 Sep 2009 15:09:56 +0200 Received: from [192.168.0.10] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id A6EA48343BB; Thu, 10 Sep 2009 15:09:41 +0200 (CEST) Message-ID: <4AA8F986.1060206@citycable.ch> Date: Thu, 10 Sep 2009 15:05:10 +0200 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Jacques Garrigue Cc: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic method. References: <4AA191F3.5000004@yziquel.homelinux.org> <4AA8F16F.1040009@citycable.ch> <20090910.214827.104047449.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20090910.214827.104047449.garrigue@math.nagoya-u.ac.jp> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 ocaml:01 syntax:01 ocaml:01 'x':01 inference:01 inference:01 polymorphic:01 polymorphic:01 typing:01 incompatible:01 caml-list:01 pair:01 pair:01 Jacques Garrigue a =C3=A9crit : > There are already polymorphic methods in ocaml. > The syntax for your example would be: >=20 > class myobject =3D object > method id : 'a. 'a -> 'a =3D fun x -> x > end Yes, I know that there are already polymorphic methods in ocaml. > A "polymorphic" keyword might seem simpler, but it would be complex to > handle the case where a polymorphic method type contains also class > parameters: >=20 > class ['a] cell (x : 'a) =3D object > method pair : 'b. 'b -> 'a * 'b =3D fun y -> (x,y) > end Indeed. But you could also write: class ['a] cell (x: 'a) =3D object polymorphic method pair y =3D (x, y) end The polymorphic keyword would only bind what can be bind. Since x is=20 already of type 'a, it would escape the scope of the 'polymorphic'=20 keyword. But y would not escape the scope of the polymorphic keyword. > 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. Well, for now, when I write methods, my methods tend to be not=20 polymorphic enough. One could keep the default behaviour without the=20 keyword, and also use the keyword polymorphic to bind only what can be=20 bound (i.e. not 'x' in your example). The problem I am facing now is cumbersome: writing types for methods=20 arguments everywhere... That's not what people would expect for type=20 inference, unfortunately. The 'polymorphic' keyword would only be a hint=20 as to how type inference would be done. This way I wouldn't have to keep=20 the typing of the method arguments in sync with the code of the method=20 (or at least, much less). By the way, I do not exactly understand the "you might end up with types=20 more polymorphic than you expected" part. > Jacques Garrigue --=20 Guillaume Yziquel http://yziquel.homelinux.org/