src/Pure/ML-Systems/exn.ML
changeset 23962 e0358fac0541
child 28444 283d5e41953d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/ML-Systems/exn.ML	Tue Jul 24 19:44:33 2007 +0200
     1.3 @@ -0,0 +1,28 @@
     1.4 +(*  Title:      Pure/ML-Systems/exn.ML
     1.5 +    ID:         $Id$
     1.6 +    Author:     Makarius
     1.7 +
     1.8 +Runtime exceptions as values.
     1.9 +*)
    1.10 +
    1.11 +structure Exn =
    1.12 +struct
    1.13 +
    1.14 +datatype 'a result =
    1.15 +  Result of 'a |
    1.16 +  Exn of exn;
    1.17 +
    1.18 +fun get_result (Result x) = SOME x
    1.19 +  | get_result _ = NONE;
    1.20 +
    1.21 +fun get_exn (Exn exn) = SOME exn
    1.22 +  | get_exn _ = NONE;
    1.23 +
    1.24 +fun capture f x = Result (f x) handle e => Exn e;
    1.25 +
    1.26 +fun release (Result y) = y
    1.27 +  | release (Exn e) = raise e;
    1.28 +
    1.29 +exception EXCEPTIONS of exn list * string;
    1.30 +
    1.31 +end;