src/Pure/Isar/spec_rules.ML
changeset 61060 a2c6f7f64aca
parent 59621 291934bac95e
child 67649 1e1782c1aedf
equal deleted inserted replaced
61059:0306e209fa9e 61060:a2c6f7f64aca
    19 end;
    19 end;
    20 
    20 
    21 structure Spec_Rules: SPEC_RULES =
    21 structure Spec_Rules: SPEC_RULES =
    22 struct
    22 struct
    23 
    23 
    24 (* maintain rules *)
    24 (* rules *)
    25 
    25 
    26 datatype rough_classification = Unknown | Equational | Inductive | Co_Inductive;
    26 datatype rough_classification = Unknown | Equational | Inductive | Co_Inductive;
    27 type spec = rough_classification * (term list * thm list);
    27 type spec = rough_classification * (term list * thm list);
    28 
    28 
    29 structure Rules = Generic_Data
    29 structure Rules = Generic_Data
    38       (#1 o #2);
    38       (#1 o #2);
    39   val extend = I;
    39   val extend = I;
    40   val merge = Item_Net.merge;
    40   val merge = Item_Net.merge;
    41 );
    41 );
    42 
    42 
    43 val get = Item_Net.content o Rules.get o Context.Proof;
       
    44 val get_global = Item_Net.content o Rules.get o Context.Theory;
       
    45 
    43 
    46 val retrieve = Item_Net.retrieve o Rules.get o Context.Proof;
    44 (* get *)
    47 val retrieve_global = Item_Net.retrieve o Rules.get o Context.Theory;
    45 
       
    46 fun get_generic context =
       
    47   let
       
    48     val thy = Context.theory_of context;
       
    49     val transfer = Global_Theory.transfer_theories thy;
       
    50   in Item_Net.content (Rules.get context) |> (map o apsnd o apsnd o map) transfer end;
       
    51 
       
    52 val get = get_generic o Context.Proof;
       
    53 val get_global = get_generic o Context.Theory;
       
    54 
       
    55 
       
    56 (* retrieve *)
       
    57 
       
    58 fun retrieve_generic context =
       
    59   Item_Net.retrieve (Rules.get context)
       
    60   #> (map o apsnd o apsnd o map) (Thm.transfer (Context.theory_of context));
       
    61 
       
    62 val retrieve = retrieve_generic o Context.Proof;
       
    63 val retrieve_global = retrieve_generic o Context.Theory;
       
    64 
       
    65 
       
    66 (* add *)
    48 
    67 
    49 fun add class (ts, ths) lthy =
    68 fun add class (ts, ths) lthy =
    50   let
    69   let
    51     val cts = map (Thm.cterm_of lthy) ts;
    70     val cts = map (Thm.cterm_of lthy) ts;
    52   in
    71   in
    54       (fn phi =>
    73       (fn phi =>
    55         let
    74         let
    56           val (ts', ths') =
    75           val (ts', ths') =
    57             Morphism.fact phi (map Drule.mk_term cts @ ths)
    76             Morphism.fact phi (map Drule.mk_term cts @ ths)
    58             |> chop (length cts)
    77             |> chop (length cts)
    59             |>> map (Thm.term_of o Drule.dest_term);
    78             |>> map (Thm.term_of o Drule.dest_term)
       
    79             ||> map Thm.trim_context;
    60         in Rules.map (Item_Net.update (class, (ts', ths'))) end)
    80         in Rules.map (Item_Net.update (class, (ts', ths'))) end)
    61   end;
    81   end;
    62 
    82 
    63 fun add_global class spec =
    83 fun add_global class spec =
    64   Context.theory_map (Rules.map (Item_Net.update (class, spec)));
    84   Context.theory_map (Rules.map (Item_Net.update (class, (apsnd o map) Thm.trim_context spec)));
    65 
    85 
    66 end;
    86 end;