[MLton-commit] r5074

Stephen Weeks sweeks at mlton.org
Thu Jan 25 17:14:40 PST 2007


tweaked

----------------------------------------------------------------------

U   mltonlib/trunk/com/sweeks/basic/unstable/exn.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/com/sweeks/basic/unstable/exn.sml
===================================================================
--- mltonlib/trunk/com/sweeks/basic/unstable/exn.sml	2007-01-23 18:03:36 UTC (rev 5073)
+++ mltonlib/trunk/com/sweeks/basic/unstable/exn.sml	2007-01-26 01:14:39 UTC (rev 5074)
@@ -7,19 +7,30 @@
 
    type t = Exn.t
 
-   local
-      datatype 'a z = Ok of 'a | Raise of t
+   datatype 'a z = Ok of 'a | Raise of t
+
+   val run: (Unit.t -> 'a) -> 'a z =
+      fn t => Ok (t ()) handle e => Raise e
+
+   val eval: 'a z -> 'a =
+      fn z =>
+      case z of
+         Ok x => x
+       | Raise e => raise e
+
+   val try: (Unit.t -> 'a) * ('a -> 'b) * (t -> 'b) -> 'b =
+      fn (t, k, h) =>
+      case run t of
+         Ok x => k x
+       | Raise e => h e
+
+   fun finally (t, cleanup: Unit.t -> Unit.t) = let
+      val z = run t
+      val () = cleanup ()
    in
-      val try: (Unit.t -> 'a) * ('a -> 'b) * (t -> 'b) -> 'b =
-         fn (t, k, h) =>
-         case Ok (t ()) handle e => Raise e of
-            Ok x => k x
-          | Raise e => h e
+      eval z
    end
 
-   fun finally (thunk, cleanup: Unit.t -> Unit.t) =
-      try (thunk, fn a => (cleanup (); a), fn e => (cleanup (); raise e))
-
 end
 
 local




More information about the MLton-commit mailing list