6185
|
1 |
(* Title: Pure/context.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
|
5 |
Global theory context.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature BASIC_CONTEXT =
|
|
9 |
sig
|
|
10 |
val context: theory -> unit
|
|
11 |
val the_context: unit -> theory
|
|
12 |
end;
|
|
13 |
|
|
14 |
signature CONTEXT =
|
|
15 |
sig
|
|
16 |
include BASIC_CONTEXT
|
|
17 |
val get_context: unit -> theory option
|
|
18 |
val set_context: theory option -> unit
|
|
19 |
val reset_context: unit -> unit
|
6238
|
20 |
val setmp: theory option -> ('a -> 'b) -> 'a -> 'b
|
|
21 |
val save: ('a -> 'b) -> 'a -> 'b
|
6185
|
22 |
val >> : (theory -> theory) -> unit
|
|
23 |
end;
|
|
24 |
|
|
25 |
structure Context: CONTEXT =
|
|
26 |
struct
|
|
27 |
|
|
28 |
|
|
29 |
(* theory context *)
|
|
30 |
|
|
31 |
local
|
|
32 |
val current_theory = ref (None: theory option);
|
|
33 |
in
|
|
34 |
fun get_context () = ! current_theory;
|
|
35 |
fun set_context opt_thy = current_theory := opt_thy;
|
6238
|
36 |
fun setmp opt_thy f x = Library.setmp current_theory opt_thy f x;
|
6185
|
37 |
end;
|
|
38 |
|
|
39 |
fun the_context () =
|
|
40 |
(case get_context () of
|
|
41 |
Some thy => thy
|
|
42 |
| _ => error "Unknown theory context");
|
|
43 |
|
|
44 |
fun context thy = set_context (Some thy);
|
|
45 |
fun reset_context () = set_context None;
|
|
46 |
|
6238
|
47 |
fun save f x = setmp (get_context ()) f x;
|
|
48 |
|
6185
|
49 |
|
|
50 |
(* map context *)
|
|
51 |
|
|
52 |
nonfix >>;
|
|
53 |
fun >> f = set_context (Some (f (the_context ())));
|
|
54 |
|
|
55 |
|
|
56 |
end;
|
|
57 |
|
|
58 |
structure BasicContext: BASIC_CONTEXT = Context;
|
|
59 |
open BasicContext;
|