Version française
Home     About     Download     Resources     Contact us    
Browse thread
Ocaml compiler features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Try finally (was Re: [Caml-list] Ocaml compiler features)

Le 15 janv. 07 à 22:30, Jon Harrop a écrit :

> try ... finally is another syntax extension that I think would be  
> welcomed by
> all.

A less invasive alternative would be to add something like this to  
pervasives (taken from Leroy and Rémy's unix course [1]) :

let apply f x ~finally y =
   let res = try f x with exn -> finally y; raise exn in
   finally y;
   res

The only quirk is that when you need to introduce a local or  
anonymous function for the blocks, but I don't really care about that.

However I'm tired of copying this function over and over in my io  
intensive sources.

Best,

Daniel

[1] <http://pauillac.inria.fr/~remy/poly/system/camlunix/index.html>