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=AWL autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 3A41DBC6B for ; Tue, 8 Jan 2008 10:50:40 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAJ/VgkfUnw6Gg2dsb2JhbACCNY1jAQEBCAQGIgeYOQ X-IronPort-AV: E=Sophos;i="4.24,257,1196636400"; d="scan'208";a="5827598" Received: from pih-relay08.plus.net ([212.159.14.134]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Jan 2008 10:50:39 +0100 Received: from [80.229.56.224] (helo=beast.local) by pih-relay08.plus.net with esmtp (Exim) id 1JCB6U-0001YB-D2 for caml-list@yquem.inria.fr; Tue, 08 Jan 2008 09:50:38 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] "OCaml gives you only monomorphic methods in classes." Date: Tue, 8 Jan 2008 09:42:36 +0000 User-Agent: KMail/1.9.7 References: <200712282337.23952.jon@ffconsultancy.com> <200712290711.34066.jon@ffconsultancy.com> <20080108.113031.162099765.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20080108.113031.162099765.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801080942.36566.jon@ffconsultancy.com> X-Spam: no; 0.00; ocaml:01 milner:01 inference:01 ocaml:01 haskell:01 overloading:01 polymorphism:01 odersky:01 ocaml's:01 variants:01 lablgtk:01 pxp:01 odersky:01 non-trivial:01 co-author:01 On Tuesday 08 January 2008 02:30:31 Jacques Garrigue wrote: > From: Jon Harrop > > I just read this quote and I do not understand what it means: > > > > "In particular, the Hindley/Milner style of type inference used in > > languages such as OCaml or Haskell is incompatible with lots of > > assumptions of OO languages. One incompatibility is with overloading. > > That's why OCaml does not let you write + for both integer and floating > > point addition. Another incompatibility is with higher order > > polymorphism. That's why OCaml gives you only monomorphic methods in > > classes." - Martin Odersky > > > > 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 personally make virtually no use of OCaml's OOP capabilities at all but I 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'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. He was co-author of two papers > about extending HM with first-class polymorphism ("putting type > annotations to work") and OO (the HM(X) framework), a long time > ago too. All these extensions (including the one used in ocaml) have > drawbacks, in particular they are either verbose or have bad error > messages, or both... Yes, I believe I misinterpreted Martin's comments. My confusion surrounding Scala was why someone researching computer languages would ditch widely appreciated features in favour of adding what appear (to me) to be seriously obscure gadgets for OO junkies. I think the reason Martin is focussing on OOP is partly because it is more extreme research (whereas cloning OCaml/Haskell is not) and also because it is potentially of great value to the huge Java ecosystem (even someone high-up at Sun+Google touted Scala as an escape route for Java). That is a very different goal from trying to improve upon the current generation of functional programming languages and is completely different to what I was looking for when I found Scala. I'm actually looking for an OCaml-like language implementation better suited to my needs rather than a wholly different language. Unfortunately, I cannot imagine who, if anyone, would build such a thing as an open source project. On the other hand, many people have written to me describing why they also believe such a project would be of enormous practical value... -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e