1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
(* Copyright (C) 1999-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
*
* MLton is released under a HPND-style license.
* See the file MLton-LICENSE for details.
*)
structure DynamicWind: DYNAMIC_WIND =
struct
fun try (f: unit -> 'a, k: 'a -> 'b, h: exn -> 'b) =
let
datatype t =
A of 'a
| E of exn
in
case A (f ()) handle e => E e of
A a => k a
| E e => h e
end
fun wind (thunk, cleanup: unit -> unit) =
try (thunk, fn a => (cleanup (); a), fn e => (cleanup (); raise e))
end
|