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
有几个地方看不懂:
finally 的语法
exn 是一种类型,我们如何在模式匹配中使用它?失败的exn?
成功 (fx) 与 exn 匹配?
cleanup 和 f x 之间的关系。