1 (* Copyright (C
) 2017 Matthew Fluet
.
2 * Copyright (C
) 2005-2006 Henry Cejtin
, Matthew Fluet
, Suresh
3 * Jagannathan
, and Stephen Weeks
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
14 val history
= MLton
.Exn
.history
16 val name
= General
.exnName
18 val message
= General
.exnMessage
21 exception Match
= Match
22 exception Overflow
= Overflow
23 exception Subscript
= Subscript
26 (* would like to make the declaration
of z
in a
let inside the try function
,
27 * with 'a
as a free
type variable
. But SML
/NJ doesn
't allow it
.
29 datatype 'a z
= Ok
of 'a | Raise
of exn
31 val try
: (unit
-> 'a
) * ('a
-> 'b
) * (exn
-> 'b
) -> 'b
=
33 case Ok (t ()) handle e
=> Raise e
of
38 fun finally (thunk
, cleanup
: unit
-> unit
) =
39 try (thunk
, fn a
=> (cleanup (); a
), fn e
=> (cleanup (); raise e
))
41 fun windFail (f
: unit
-> 'a
, g
: unit
-> unit
): 'a
=
42 f () handle ex
=> (g (); raise ex
)
44 fun 'a
withEscape (f
: ('a
-> 'b
) -> 'a
): 'a
=
48 f (fn x
=> raise E x
) handle E x
=> x