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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 420CFBC6C for ; Mon, 28 Jan 2008 17:45:30 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADKVnUfAXQInh2dsb2JhbACQKgEBAQgKKZpl X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208";a="8457978" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 28 Jan 2008 17:45:29 +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 m0SGjTkB007367 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 28 Jan 2008 17:45:29 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAFuVnUfBvsFJh2dsb2JhbACQKgEBAQgKKZpm X-IronPort-AV: E=Sophos;i="4.25,260,1199660400"; d="scan'208";a="7338384" Received: from hedwig2.umh.ac.be (HELO hedwig1.umh.ac.be) ([193.190.193.73]) by mail1-smtp-roc.national.inria.fr with ESMTP; 28 Jan 2008 17:45:28 +0100 Received: from poincare.swapping.umh.ac.be ([10.102.100.12]) by hedwig1.umh.ac.be (8.14.2/8.14.2) with ESMTP id m0SGkEDW3682422; Mon, 28 Jan 2008 17:46:14 +0100 Received: from localhost ([127.0.0.1] ident=trch) by poincare.swapping.umh.ac.be with esmtp (Exim 4.68) (envelope-from ) id 1JJX6m-0004Zk-BX; Mon, 28 Jan 2008 17:45:20 +0100 Date: Mon, 28 Jan 2008 17:45:20 +0100 (CET) Message-Id: <20080128.174520.980688744689375681.Christophe.Troestler+ocaml@umh.ac.be> To: nicolas.pouillard@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] [OSR] OCaml Standard Recommandation Process From: Christophe TROESTLER In-Reply-To: <1201537038-sup-3774@ausone.inria.fr> References: <200801281525.12651.jon@ffconsultancy.com> <20080128.170610.265034237530039453.Christophe.Troestler+ocaml@umh.ac.be> <1201537038-sup-3774@ausone.inria.fr> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons-Hainaut X-Mailer: Mew version 5.2.52 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.1 (www dot roaringpenguin dot com slash mimedefang) X-Miltered: at concorde with ID 479E06A9.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 0100,:01 ocaml's:01 translated:01 wrote:01 wrote:01 caml-list:01 umh:01 binding:02 binding:02 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" ? ChriS