Commits

camlspotter  committed 809f23b

protect

  • Participants
  • Parent commits 4268430

Comments (0)

Files changed (2)

 let (^.) f g = fun x -> f (g x)
 let (^$) f x = f x
 
+let protect f a ~finally =
+  match try `Ok (f a) with e -> `Exn e with
+  | `Ok v -> finally (); v
+  | `Exn e -> finally (); raise e
+
+    
   (** funciton composition: Haskell's (.) *)
 val (^$) : ('a -> 'b) -> 'a -> 'b
   (** Haskell's ($) *)
+
+val protect : ('a -> 'b) -> 'a -> finally: (unit -> unit) -> 'b