Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Chet Murthy <chet@w...>
Subject: Re: [Caml-list] Resource acquisition is initialization

Blair,

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

E.g.

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.

--chet--
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners