OSDN Git Service

update base
authormzp <mzpppp@gmail.com>
Wed, 21 Oct 2009 22:56:39 +0000 (07:56 +0900)
committermzp <mzpppp@gmail.com>
Wed, 21 Oct 2009 22:56:39 +0000 (07:56 +0900)
base/base.ml

index 9c708e5..ed4b4aa 100644 (file)
@@ -108,24 +108,21 @@ let string_of_char =
 let hex =
   Printf.sprintf "0x%x"
 
-let todo x =
-  failwith x
-
 let open_out_with path f =
-  let ch =
-    open_out_bin path in
-  let s =
-    f ch in
-    close_out ch;
-    s
+  open_out_bin path
+  +> maybe f
+  +> tee (fun _ -> close_out ch)
+  +> function
+      `Val v ->  v
+    | `Error e -> raise e
 
 let open_in_with path f =
-  let ch =
-    open_in_bin path in
-  let s =
-    f ch in
-    close_in ch;
-    s
+  open_in_bin path
+  +> maybe f
+  +> tee (fun _ -> close_in ch)
+  +> function
+      `Val v ->  v
+    | `Error e -> raise e
 
 let undefined =  Obj.magic 42
 let undef     = undefined