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 60B71BC6B for ; Sun, 9 Dec 2007 23:21:43 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkchAN74W0fUnw7XYmdsb2JhbACCOI0hFQQGEBk X-IronPort-AV: E=Sophos;i="4.23,274,1194217200"; d="scan'208";a="6642809" Received: from fhw-relay07.plus.net ([212.159.14.215]) by mail3-smtp-sop.national.inria.fr with ESMTP; 09 Dec 2007 23:21:42 +0100 Received: from [80.229.56.224] (helo=beast.local) by fhw-relay07.plus.net with esmtp (Exim) id 1J1UWs-0008BG-7W for caml-list@yquem.inria.fr; Sun, 09 Dec 2007 22:21:42 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Ask for a more efficient way to deallocate memory (full version) Date: Sun, 9 Dec 2007 22:12:30 +0000 User-Agent: KMail/1.9.5 References: <39980.81.57.198.61.1197236388.squirrel@webmail.lpn.cnrs.fr> In-Reply-To: <39980.81.57.198.61.1197236388.squirrel@webmail.lpn.cnrs.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200712092212.30563.jon@ffconsultancy.com> X-Spam: no; 0.00; opendir:01 higher-order:01 ocaml:01 frog:98 wrote:01 unix:01 unix:01 caml-list:01 referenced:02 idiomatic:02 deallocate:03 cnrs:06 olivier:07 efficient:07 efficient:07 On Sunday 09 December 2007 21:39, Fabrice.Pardo@lpn.cnrs.fr wrote: > Hello, and sorry for my previous unfinished message. > > As the function Unix.opendir returns a value, > we can expect that Unix.closedir will be automatically > called when the dir_handle value is no more referenced. You cannot expect that. > ... > My question is how to write a code as efficient > as it would be possible using a reference-counted language. RAII wrapped in a higher-order function as Olivier described is the idiomatic solution in OCaml. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e