The default value is provided not as a direct value of type ['a]
- but as a thunk [(unit -> 'a)], since such a value
need to be created
+ but as a thunk [(unit -> 'a)], since such a value be created
let catch_exn f = catch (fun ~fail -> try f () with e -> fail e)
+let from_Ok to_exn = function
+ | `Error e -> raise (to_exn e)
Any exception raised in [f ~fail] is not caught.
-val catch_exn : (unit -> 'a) -> [>
`Error of exn | `Ok of 'a ]
+val catch_exn : (unit -> 'a) -> [> ]
(** [catch_exn f] runs [f ()].
If [f ()] returns a value [v] then [catch f] returns [`Ok v].
If an exception [exn] raised in [f ()], [catch f] returns [`Error exn].
+val from_Ok : ('error -> exn) -> [< ('a, 'error) t] -> 'a