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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 982CBBC6C for ; Mon, 28 Jan 2008 16:30:55 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HAHuEnUfAXQImh2dsb2JhbACCNo10AQEBCAopml8 X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208";a="21892852" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Jan 2008 16:30:55 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m0SFUsL2028087 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 28 Jan 2008 16:30:54 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HAAKEnUfUnw6EgGdsb2JhbACCNo10AQEJCiIHml0 X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208";a="7334800" Received: from pih-relay05.plus.net ([212.159.14.132]) by mail1-smtp-roc.national.inria.fr with ESMTP; 28 Jan 2008 16:30:54 +0100 Received: from [80.229.56.224] (helo=beast.local) by pih-relay05.plus.net with esmtp (Exim) id 1JJVwc-0004Vd-7D; Mon, 28 Jan 2008 15:30:46 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: Brian Hurt Subject: Re: [Caml-list] [OSR] OCaml Standard Recommandation Process Date: Mon, 28 Jan 2008 15:25:12 +0000 User-Agent: KMail/1.9.7 References: <1201440183.6302.27.camel@Blefuscu> <200801281204.00689.jon@ffconsultancy.com> <479DE545.9050306@janestcapital.com> In-Reply-To: <479DE545.9050306@janestcapital.com> Cc: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801281525.12651.jon@ffconsultancy.com> X-Plusnet-Relay: 508937d609945a977ad49655b6b6f118 X-Miltered: at discorde with ID 479DF52E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 bindings:01 deallocation:01 translated:01 ocaml:01 overloading:01 overloading:01 inference:01 ad-hoc:01 vectors:01 matrices:01 inference:01 foo:01 non-trivial:01 predictable:01 On Monday 28 January 2008 14:23:01 you wrote: > Jon Harrop wrote: > >There are also many features that I would like to steal from other > > languages: > > > >. The IDisposable interface from .NET and F#'s "use" bindings. > > Is there a reason that Gc.finalise doesn't work? Absolutely: Gc.finalise is only probabilistic whereas IDisposable is deterministic. IDisposable guarantees deallocation of resources by a certain point. (This is why you should never use Gc.finalise alone to manage the collection of external resources!) So you write a "use" binding: let read_first_line file = use ch = open_in file in input_line ch and it gets translated into: let read_first_line file = let ch = open_in file in try input_line ch finally ch#dispose where the "dispose" method that was automatically inserted at the end of the scope of the "use" binding calls "close_in" in this case to deallocate the external resource (a file handle in this case but it could be anything with a dispose method). This is easy to implement and will remove a world of pain when doing IO in OCaml. > >and some more involved ones like operator overloading. > > I *hate* operator overloading. My experience in C++ is for every time > this feature is used legitimately (i.e. to implement complex numbers or > whatever), it's abused 10 times- and that's ignoring C++'s use of the > bit shift operators << and >> for I/O, and the use of + for string > concatentation, both of which I'd argue really should be considered > abuses, as far as I'm concerned. And this is ignoring the difficulty of type > inference in the presence of overloaded operators. You're looking in the wrong direction. Look at F# to see how OCaml + overloading done right can be hugely beneficial. OCaml has fallen far too far behind to catch up completely but we could take some baby steps in this direction, just like SML's ad-hoc polymorphic approach but with a wider range of types (complexes, vectors, matrices). This is fairly easy to implement and, again, will remove a world of pain when doing arithmetic in OCaml. > The best way to handle this IMHO is Haskell-style type classes. Which > solves the whole type inference problem, and rules most of what I > consider abuses of operator overloading (for example, if you have a '+' > operator, you also have to have a '*' operator- and what is "foo" * > "bar"?). But this is a very non-trivial change to the language. Type classes are more powerful but they also make performance less predictable (the dictionary may or may not be optimized away). They are also unachievable, as you say. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e