src/Pure/context.ML
changeset 6310 353a8a9d9d2c
parent 6261 6dc692fb3d28
child 8348 ebbbfdb35c84
equal deleted inserted replaced
6309:ca52347e259a 6310:353a8a9d9d2c
    16   include BASIC_CONTEXT
    16   include BASIC_CONTEXT
    17   val get_context: unit -> theory option
    17   val get_context: unit -> theory option
    18   val set_context: theory option -> unit
    18   val set_context: theory option -> unit
    19   val reset_context: unit -> unit
    19   val reset_context: unit -> unit
    20   val setmp: theory option -> ('a -> 'b) -> 'a -> 'b
    20   val setmp: theory option -> ('a -> 'b) -> 'a -> 'b
    21   val fetch: theory option -> ('a -> 'b) -> 'a -> 'b * theory option
    21   val pass: theory option -> ('a -> 'b) -> 'a -> 'b * theory option
    22   val fetch_theory: theory -> ('a -> 'b) -> 'a -> 'b * theory
    22   val pass_theory: theory -> ('a -> 'b) -> 'a -> 'b * theory
    23   val save: ('a -> 'b) -> 'a -> 'b
    23   val save: ('a -> 'b) -> 'a -> 'b
    24   val >> : (theory -> theory) -> unit
    24   val >> : (theory -> theory) -> unit
    25 end;
    25 end;
    26 
    26 
    27 structure Context: CONTEXT =
    27 structure Context: CONTEXT =
    44   | _ => error "Unknown theory context");
    44   | _ => error "Unknown theory context");
    45 
    45 
    46 fun context thy = set_context (Some thy);
    46 fun context thy = set_context (Some thy);
    47 fun reset_context () = set_context None;
    47 fun reset_context () = set_context None;
    48 
    48 
    49 fun fetch opt_thy f x =
    49 fun pass opt_thy f x =
    50   setmp opt_thy (fn x => let val y = f x in (y, get_context ()) end) x;
    50   setmp opt_thy (fn x => let val y = f x in (y, get_context ()) end) x;
    51 
    51 
    52 fun fetch_theory thy f x =
    52 fun pass_theory thy f x =
    53   (case fetch (Some thy) f x of
    53   (case pass (Some thy) f x of
    54     (y, Some thy') => (y, thy')
    54     (y, Some thy') => (y, thy')
    55   | (_, None) => error "Missing ML theory context");
    55   | (_, None) => error "Missing ML theory context");
    56 
    56 
    57 fun save f x = setmp (get_context ()) f x;
    57 fun save f x = setmp (get_context ()) f x;
    58 
    58