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
[Caml-list] Resource acquisition is initialization
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-12-12 (00:29)
From: Chet Murthy <chet@w...>
Subject: Re: [Caml-list] Resource acquisition is initialization


Perhaps, what you want is a "try_finally" for Ocaml.


let finally f arg finf =
  let rv = try Inl(f arg) with e -> Inr e
  in (try finf arg (match rv with Inl v -> Some v | Inr _ -> None) with e -> ());
	match rv with
		Inl v -> v
	  | Inr e -> raise e

Now, while this code isn't the most efficient, I believe (haven't
checked the details) that with sufficient partial evaluation and some
code-rearranging which is semantics-preserving, this code becomes
efficient, albeit somewhat larger than perhaps entirely desirable.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: