Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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;

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.



[1] <>