From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A9778BC84 for ; Mon, 7 Mar 2005 19:47:03 +0100 (CET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.201]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j27Il24R019380 for ; Mon, 7 Mar 2005 19:47:03 +0100 Received: by rproxy.gmail.com with SMTP id g11so2119831rne for ; Mon, 07 Mar 2005 10:47:02 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=WqCEUq5Of7SrJTQTFnMF55XZwenSZFYps1zBlBooNOpuoIioTxmxzgGiH7d+cbNfZsBQr0XYkWgsSnLSB/kPCABD2mLwP+ay0OHd8zQtXEotnPcb5HITzyAk3hLSzz3GrEPscIGAOvO3ZoV3dc9rVtrvNky1y97XYNgvM33Ms9I= Received: by 10.38.125.36 with SMTP id x36mr30279rnc; Mon, 07 Mar 2005 10:47:01 -0800 (PST) Received: by 10.38.86.60 with HTTP; Mon, 7 Mar 2005 10:47:01 -0800 (PST) Message-ID: <877e9a1705030710476502ad31@mail.gmail.com> Date: Mon, 7 Mar 2005 13:47:01 -0500 From: Michael Walter Reply-To: Michael Walter To: caml-list@yquem.inria.fr, Jon Harrop Subject: Re: [Caml-list] Re: exception safety / RAII ? In-Reply-To: <200503071729.20117.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <293072a520e3724a0497e6456a8675be@mac.com> <200503071330.49084.jon@jdh30.plus.com> <877e9a170503070721b2e0298@mail.gmail.com> <200503071729.20117.jon@jdh30.plus.com> X-Miltered: at nez-perce with ID 422CA1A6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 o'caml:01 finalizers:01 o'caml:01 wrote:01 wrote:01 exception:01 exception:01 dependency:01 graph:01 reasoning:01 finalization:01 objects:02 limitations:02 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On Mon, 7 Mar 2005 17:29:19 +0000, Jon Harrop wrote: > On Monday 07 March 2005 15:21, Michael Walter wrote: > > On Mon, 7 Mar 2005 13:30:48 +0000, Jon Harrop wrote: > > > I don't know C#, but when would you want to deallocate a resource before > > > all references to it have disappeared? > > > > I never had such a desire. > > Would you mind elaborating a little on what you do desire, i.e. what does > "using" do in C#, when would you use it and how does this relate to OCaml? Sure. I hope the following answers all three questions at once: let using resource thunk = try let result = thunk resource in dispose resource; result with any_exception -> dispose resource; raise any_exception My O'Caml is not very fluent, possible "dispose resource" should read "resource # dispose". Basically, the idea is to deterministically clean up resources, as early as possible (yes, "but it's not as early as possible" is besides the point :-). In my experience this simplifies resource management and reasoning about it. > Presumably this is only difficult in the more complicated case of a general > dependency graph between objects? In particular, one which has cycles. What > kinds of programs require such sophistication? I have no idea about with finalizers in O'Caml (hence my more broad/general statement), but in other languages I've worked with there are several limitations which all basically origin in the fact that finalization order in these languages was non-deterministic. Greetings, Michael