Commits

camlspotter committed 008acc3

from_Ok

Comments (0)

Files changed (3)

     [default None f = f ()]
 
     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 may be created
     dynamically.
 *)
 
 
 let catch_exn f = catch (fun ~fail -> try f () with e -> fail e)
   
+let from_Ok to_exn = function
+  | `Ok v -> v
+  | `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) -> [> ('a, exn) t ]
 (** [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