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,HTML_MESSAGE autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 1C870BC6C for ; Mon, 28 Jan 2008 17:38:14 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAPKTnUfAXQInh2dsb2JhbACCOzUpiWqDJwEBAQgKKZpr X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208,217";a="8457688" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 28 Jan 2008 17:38:13 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m0SGcBHL007049 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 28 Jan 2008 17:38:13 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HAD2TnUdCm3xr/2dsb2JhbACCOzUpiWqeVg X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208,217";a="7338023" Received: from janestcapital.com (HELO smtp.janestcapital.com) ([66.155.124.107]) by mail1-smtp-roc.national.inria.fr with ESMTP; 28 Jan 2008 17:38:09 +0100 Received: from [172.25.129.161] [38.96.172.125] by janestcapital.com with ESMTP (SMTPD-9.10) id A4EE0304; Mon, 28 Jan 2008 11:38:06 -0500 Message-ID: <479E04E6.5000303@janestcapital.com> Date: Mon, 28 Jan 2008 11:37:58 -0500 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jon Harrop Cc: caml-list@inria.fr Subject: Re: [Caml-list] [OSR] OCaml Standard Recommandation Process References: <1201440183.6302.27.camel@Blefuscu> <200801281204.00689.jon@ffconsultancy.com> <479DE545.9050306@janestcapital.com> <200801281525.12651.jon@ffconsultancy.com> In-Reply-To: <200801281525.12651.jon@ffconsultancy.com> Content-Type: multipart/alternative; boundary="------------090206030202010809040308" X-Miltered: at concorde with ID 479E04F3.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 bindings:01 deallocation:01 translated:01 monads:01 ocaml:01 bindings:01 deallocation:01 translated:01 monads:01 garbage:01 garbage:01 wrote:01 wrote:01 caml-list:01 This is a multi-part message in MIME format. --------------090206030202010809040308 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Jon Harrop wrote: >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 > > What happens when I write: let broken file = use ch = open_in file in (fun () -> input_line ch) ? Or some other tricky way to let ch escape the scope? Monads strike me as being a better way to do this, but again, we're talking about deep changes to Ocaml. The alternative- wait until the object is garbage collected, depends upon the form of the garbage collector. Brian --------------090206030202010809040308 Content-Type: text/html; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit Jon Harrop wrote:
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
  
What happens when I write:
    let broken file =
       use ch = open_in file in
       (fun () -> input_line ch)
?  Or some other tricky way to let ch escape the scope?

Monads strike me as being a better way to do this, but again, we're talking about deep changes to Ocaml.  The alternative- wait until the object is garbage collected, depends upon the form of the garbage collector.

Brian

--------------090206030202010809040308--