[MLton-commit] r4887

Vesa Karvonen vesak at mlton.org
Thu Nov 30 07:55:19 PST 2006


Added basic exception handling operations to Exn : EXN.

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

U   mltonlib/trunk/com/ssh/extended-basis/unstable/detail/exn.sml
U   mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb
U   mltonlib/trunk/com/ssh/extended-basis/unstable/public/exn.sig

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

Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/exn.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/exn.sml	2006-11-30 15:53:21 UTC (rev 4886)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/exn.sml	2006-11-30 15:55:18 UTC (rev 4887)
@@ -8,4 +8,9 @@
    open Exn Ext.Exn
    val name = General.exnName
    val message = General.exnMessage
+   fun apply f x = Sum.INR (f x) handle e => Sum.INL e
+   fun eval th = apply th ()
+   fun throw e = raise e
+   fun try (th, fv, fe) = Sum.sum (fe, fv) (eval th)
+   fun finally (th, ef) = try (th, Effect.past ef, throw o Effect.past ef)
 end

Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb	2006-11-30 15:53:21 UTC (rev 4886)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb	2006-11-30 15:55:18 UTC (rev 4887)
@@ -39,11 +39,6 @@
          basis Ext = bas detail/$(SML_COMPILER)/extensions.mlb end
 
          basis Fn = bas public/fn.sig detail/fn.sml end
-         basis Exn = let
-            open Ext
-         in
-            bas public/exn.sig detail/exn.sml end
-         end
          basis Unit = bas public/unit.sig end
          basis Sq = bas public/sq.sig detail/sq.sml end
          basis UnOp = bas public/un-op.sig detail/un-op.sml end
@@ -82,6 +77,11 @@
             end
          end
          basis Sum = let open Fn in bas public/sum.sig detail/sum.sml end end
+         basis Exn = let
+            open Effect Ext Sum
+         in
+            bas public/exn.sig detail/exn.sml end
+         end
          basis Emb = let
             open Fn Products
          in

Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/exn.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/exn.sig	2006-11-30 15:53:21 UTC (rev 4886)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/exn.sig	2006-11-30 15:55:18 UTC (rev 4887)
@@ -9,6 +9,29 @@
    type t = exn
    (** Convenience alias. *)
 
+   (** == Exception Handling == *)
+
+   val apply : ('a -> 'b) -> 'a -> (t, 'b) Sum.t
+   (** Perform an application ({apply f x = INR (f x) handle e => INL e}). *)
+
+   val eval : 'a Thunk.t -> (t, 'a) Sum.t
+   (** Evaluate a thunk ({eval th = INR (th ()) handle e => INL e}). *)
+
+   val finally : 'a Thunk.t * Unit.t Effect.t -> 'a
+   (** {finally (th, ef) = try (th, past ef, throw o past ef)}. *)
+
+   val throw : t -> 'a
+   (** Raise exception ({throw exn = raise exn}). *)
+
+   val try : 'a Thunk.t * ('a -> 'b) * (t -> 'b) -> 'b
+   (**
+    * Try-in-unless ({try (th, fv, fe) = sum (fv, fe) (eval th)}).  {try}
+    * facilitates fine control over exception handling.  {try} implements
+    * the try-in-unless construct of Benton and Kennedy.
+    *)
+
+   (** == Examining Exceptions == *)
+
    val addMessager : (t -> String.t Option.t) Effect.t
    (**
     * Adds a pretty-printer to be used by {message} for converting
@@ -16,8 +39,6 @@
     * recently added to least recently added.
     *)
 
-   (** == Examining Exceptions == *)
-
    val message : t -> String.t
    (** Same as {General.exnMessage}. *)
 




More information about the MLton-commit mailing list