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=1.1 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 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 2593ABC6B for ; Tue, 8 Jan 2008 18:29:42 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACNCg0dFEXUJnmdsb2JhbACQGwEBAQEHBAYpmGME X-IronPort-AV: E=Sophos;i="4.24,258,1196636400"; d="scan'208";a="21027139" Received: from mail7.sea5.speakeasy.net ([69.17.117.9]) by mail4-smtp-sop.national.inria.fr with ESMTP; 08 Jan 2008 18:29:41 +0100 Received: (qmail 22062 invoked from network); 8 Jan 2008 17:29:39 -0000 Received: from shell2.sea5.speakeasy.net ([69.17.116.3]) (envelope-sender ) by mail7.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 8 Jan 2008 17:29:39 -0000 Date: Tue, 8 Jan 2008 09:29:39 -0800 (PST) From: brogoff To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] "OCaml gives you only monomorphic methods in classes." In-Reply-To: <200801080942.36566.jon@ffconsultancy.com> Message-ID: References: <200712282337.23952.jon@ffconsultancy.com> <200712290711.34066.jon@ffconsultancy.com> <20080108.113031.162099765.garrigue@math.nagoya-u.ac.jp> <200801080942.36566.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; ocaml:01 ocaml:01 translating:01 okasaki's:01 rewrote:01 polymorphism:01 recursion:01 ocaml's:01 variants:01 lablgtk:01 pxp:01 clashes:01 variants:01 odersky:01 non-trivial:01 On Tue, 8 Jan 2008, Jon Harrop wrote: > On Tuesday 08 January 2008 02:30:31 Jacques Garrigue wrote: > > From: Jon Harrop > > > In what way must methods be monomorphic in OCaml classes? > > > > They don't. With the restriction that the types of polymorphic > > methods cannot be inferred. There is also another subtle > > limitation, that object are only allowed to have regular > > types. As a result, one cannot write a polymorphic map method in > > ocaml, but this is possible in Java 2 or Scala. > > This begs a question for me: have people used this functionality in their > OCaml code? I don't understand your question. How could we use this functionality in our OCaml code if it doesn't exist? You must mean something else, perhaps "do I use polymorphic methods in my OCaml code?". Not now. I did when translating some purely functional data structures from Okasaki's book to OCaml, then rewrote them using the higher order polymorphism of record fields, which we got at the same time, a workaround to the lack of polymorphic recursion in OCaml. > I personally make virtually no use of OCaml's OOP capabilities at all but I Very punny ;-) > make a lot of use of polymorphic variants. In all but a few cases, objects > seem to be very rarely used by other people in OCaml code. The only notable > exceptions I can think of are LablGTK2 and PXP. I use them when I have record field name clashes and I decide that this aspect of OCaml records hinders rather than helps readability. It is an interesting topic, certainly. Pattern matching is less useful on records than variants (IMO of course) so the fact that we don't have it on objects doesn't bother me all that much. But in my experience I need to provide a lot more explicit typing when using the OOP features than I'm used to, in order to get comprehensible error messages. > > I'm quite sure that Martin Odersky is aware of this. I would rather > > interpret his quote as meaning that you have to extend HM in a > > non-trivial way to allow this. If the original quote was accurate, then I think this is quite generous, as it seemed the statement was 'OCaml doesn't have polymorphic methods, period-end-of-story". Scala does look very interesting though, and if I need to work in a JVM environment I'll seriously consider using it. -- Brian