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.0 required=5.0 tests=AWL,SPF_NEUTRAL 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 3DAA7BC6C for ; Mon, 28 Jan 2008 17:51:19 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEuWnUfAXQInh2dsb2JhbACQKgEBAQgKKZUZhVM X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208";a="8458201" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 28 Jan 2008 17:51:18 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m0SGpB5R007630 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 28 Jan 2008 17:51:18 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAMKWnUfRVYC8mGdsb2JhbACQKgEBAQEBBgQGBwoWlR2FTw X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208";a="6664714" Received: from fk-out-0910.google.com ([209.85.128.188]) by mail2-smtp-roc.national.inria.fr with ESMTP; 28 Jan 2008 17:51:18 +0100 Received: by fk-out-0910.google.com with SMTP id z22so1426999fkz.9 for ; Mon, 28 Jan 2008 08:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=hLz8aumlDPK7qqZpQlxUTiGkb3iog0f8NYyMsP4MbS0=; b=WZqv8X9LTAXX1O/hh4B0hTyuzBMBHvv0+LiT9tIok+WSsqV5b9sug5ccA44u68e6WYUio7s0iS+0zx9FgsZLVXoZqn51EAqFW+Pwspwtx6SX6f7BpJzZcxwKXf3lHom5vNrGxKujkVbIKcZ5mwmfZThrlfcowQgkLQmeqoWXJMs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=CReT7iELkPuFGD9ezbc7v2hUsPovBO130WfXreIsURVTUthPIPCs7c/LQJPMJY4d/KjsDQVIm76Oqigwt+vtk9KMvuI8tuDTfOix+5iRFPqo4ak68UUCCJr9Q5mx9uaMteV/X5tWsvaVe4P1MnnSfDfjl1Pgor7w0m90+71y9/M= Received: by 10.78.183.8 with SMTP id g8mr7627675huf.42.1201539077674; Mon, 28 Jan 2008 08:51:17 -0800 (PST) Received: by 10.78.25.10 with HTTP; Mon, 28 Jan 2008 08:51:17 -0800 (PST) Message-ID: <95513600801280851x728c1fa8ta0ba67c902c0aa7c@mail.gmail.com> Date: Mon, 28 Jan 2008 17:51:17 +0100 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: "Christophe TROESTLER" Subject: Re: [Caml-list] [OSR] OCaml Standard Recommandation Process Cc: caml-list@inria.fr In-Reply-To: <20080128.174520.980688744689375681.Christophe.Troestler+ocaml@umh.ac.be> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200801281525.12651.jon@ffconsultancy.com> <20080128.170610.265034237530039453.Christophe.Troestler+ocaml@umh.ac.be> <1201537038-sup-3774@ausone.inria.fr> <20080128.174520.980688744689375681.Christophe.Troestler+ocaml@umh.ac.be> X-Google-Sender-Auth: 79b32f83c734e157 X-Miltered: at concorde with ID 479E07FF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 ocaml:01 christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 0100,:01 ocaml's:01 translated:01 datatype:01 28,:98 wrote:01 wrote:01 On Jan 28, 2008 5:45 PM, Christophe TROESTLER wrote: > > On Mon, 28 Jan 2008 17:20:16 +0100, Nicolas Pouillard wrote: > > > > Excerpts from christophe.troestler+ocaml's message of Mon Jan 28 17:06:10 +0100 2008: > > > On Mon, 28 Jan 2008 15:25:12 +0000, Jon Harrop wrote: > > > > > > > > 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). > > > > > > What is wrong with > > > > > > let read_first_line file = > > > with_open_in file begin fun ch -> > > > input_line ch > > > end > > > > This code has nothing wrong but with_open_in (even if it's very useful) is > > not resource safe. This is because the in_channel can escape it's scope. > > > > | let ch = with_open_in file (fun x -> x) in > > | input_line ch > > > > This program is obviously wrong but still show that with_open_in is not safe. > > Right but how is it different with "use" ? It's basically the same. But with "use" (or "using" in C#), you don't have to write the "with_open_in" wrapper in the first place because the finalizing function is implicit, it's the method called "Dispose". Using this scheme with OCaml would mean that any resource-using datatype has to be an object (not really the case right now). -- Olivier