From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p196PNnB008899 for ; Wed, 9 Feb 2011 07:25:23 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtEAANzBUU3RVdo2mGdsb2JhbACEHJMLjhUIFQEBAQEBCAkMBxEko0mJUDyCF4RaL4hZAQEDBYEigz52BItuiDI6 X-IronPort-AV: E=Sophos;i="4.60,445,1291590000"; d="scan'208";a="90943178" Received: from mail-yi0-f54.google.com ([209.85.218.54]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-MD5; 09 Feb 2011 07:25:18 +0100 Received: by yie19 with SMTP id 19so2659209yie.27 for ; Tue, 08 Feb 2011 22:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=rs2GSQvooX4HBa5uGkxndsRLMCjqYWuDZgbzXtrYmUg=; b=hJrJdh3+R63jH6oIcQg+ulyc8cPna1BadnXdD/dtDAz5tSFfnxNIW9+V+BpTsKv9H+ JkZdsxTMaMK4z6vGk+2SUrjjqKQsyH+jl4eqECn021vQpH75ZnqPC0WPMFhoOpV+GDU5 N4uYaC5kreiaJgLCXb7iUxaK2S3YtUYiIi9TY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=HqtapzpG3h/ibXrcAH5XQb2Zw2kviqKyndV09sm77a6rQMXBjp+z/L4UdZLc0lRwMm RsIFCNNwksTZuUGniioaW6IAiDQ37jVM/J3s0F8JgMU9sYBR+jB0TWT1RkJrFtcp0H0Z gvf5iWxyNX92xaVW9FIA1WlavsfumIM0Jet6U= MIME-Version: 1.0 Received: by 10.151.13.1 with SMTP id q1mr1217852ybi.86.1297232717015; Tue, 08 Feb 2011 22:25:17 -0800 (PST) Received: by 10.150.178.16 with HTTP; Tue, 8 Feb 2011 22:25:16 -0800 (PST) In-Reply-To: <50AF76A1-30E0-4735-AFB2-88BB603899CE@ezabel.com> References: <50AF76A1-30E0-4735-AFB2-88BB603899CE@ezabel.com> Date: Wed, 9 Feb 2011 08:25:16 +0200 Message-ID: From: dmitry grebeniuk To: caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p196PNnB008899 Subject: Re: [Caml-list] Scoped Bound Resource Management just for C++? > One of the benefits, in my opinion, of C++ is SBRM.  You can reason about > the lifetime of an object and have an give yourself guarantees about its > clean up.  The method of initialization and clean up are also consistent for > every object in the language. I'm using with-idiom for managing external resources (90% of uses of i/o channels, network connections, database connections), I find it helpful. With-function closes/frees resource when user-function returns result or raises exception. A typical with-function can have a signature like: val with_file_in_bin : string -> (in_channel -> 'a) -> 'a Of course, it's not safe in general case, since you can store in_channel into some external reference or even return it, but I have never made such mistakes (so far).