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