type 'a result =
Success of 'a
| Failed of exn
let finally f x cleanup =
let result =
try Success (f x) with
exn -> Failed exn
in
cleanup ();
match result with
Success y -> y
| Failed exn -> raise exn
There are several places I do not understand:
the syntax of finally
exn is a type, how can we use it in a pattern matching? Failed exn?
Success (f x) matched with exn?
relationship between cleanup and f x.