src/Pure/Isar/generic_target.ML
changeset 71788 ca3ac5238c41
parent 71178 c7d4f2ab40b9
child 72505 974071d873ba
equal deleted inserted replaced
71787:acfe72ff00c2 71788:ca3ac5238c41
    16   (*background primitives*)
    16   (*background primitives*)
    17   val background_foundation: ((binding * typ) * mixfix) * (binding * term) ->
    17   val background_foundation: ((binding * typ) * mixfix) * (binding * term) ->
    18     term list * term list -> local_theory -> (term * thm) * local_theory
    18     term list * term list -> local_theory -> (term * thm) * local_theory
    19   val background_declaration: declaration -> local_theory -> local_theory
    19   val background_declaration: declaration -> local_theory -> local_theory
    20   val background_abbrev: binding * term -> term list -> local_theory -> (term * term) * local_theory
    20   val background_abbrev: binding * term -> term list -> local_theory -> (term * term) * local_theory
       
    21   val add_foundation_interpretation: (binding * (term * term list) -> Context.generic -> Context.generic) ->
       
    22     theory -> theory
    21 
    23 
    22   (*nested local theories primitives*)
    24   (*nested local theories primitives*)
    23   val standard_facts: local_theory -> Proof.context -> Attrib.fact list -> Attrib.fact list
    25   val standard_facts: local_theory -> Proof.context -> Attrib.fact list -> Attrib.fact list
    24   val standard_notes: (int * int -> bool) -> string -> Attrib.fact list ->
    26   val standard_notes: (int * int -> bool) -> string -> Attrib.fact list ->
    25     local_theory -> local_theory
    27     local_theory -> local_theory
   161 
   163 
   162 
   164 
   163 
   165 
   164 (** background primitives **)
   166 (** background primitives **)
   165 
   167 
       
   168 structure Foundation_Interpretations = Theory_Data
       
   169 (
       
   170   type T = (binding * (term * term list) -> Context.generic -> Context.generic) Inttab.table;
       
   171   val empty = Inttab.empty;
       
   172   val extend = I;
       
   173   val merge = Inttab.merge (K true);
       
   174 );
       
   175 
       
   176 fun add_foundation_interpretation f =
       
   177   Foundation_Interpretations.map (Inttab.update_new (serial (), f));
       
   178 
       
   179 fun foundation_interpretation binding_const_params lthy =
       
   180   let
       
   181     val interps = Foundation_Interpretations.get (Proof_Context.theory_of lthy);
       
   182     val interp = Inttab.fold (fn (_, f) => f binding_const_params) interps;
       
   183   in
       
   184     lthy
       
   185     |> Local_Theory.background_theory (Context.theory_map interp)
       
   186     |> Local_Theory.map_contexts (K (Context.proof_map interp))
       
   187   end;
       
   188 
   166 fun background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
   189 fun background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
   167   let
   190   let
   168     val params = type_params @ term_params;
   191     val params = type_params @ term_params;
       
   192     val target_params = type_params
       
   193       @ take_prefix is_Free (Variable.export_terms lthy (Local_Theory.target_of lthy) term_params);
   169     val mx' = check_mixfix_global (b, null params) mx;
   194     val mx' = check_mixfix_global (b, null params) mx;
   170 
   195 
   171     val (const, lthy2) = lthy
   196     val (const, lthy2) = lthy
   172       |> Local_Theory.background_theory_result (Sign.declare_const lthy ((b, U), mx'));
   197       |> Local_Theory.background_theory_result (Sign.declare_const lthy ((b, U), mx'));
   173     val lhs = Term.list_comb (const, params);
   198     val lhs = Term.list_comb (const, params);
   174 
   199 
   175     val ((_, def), lthy3) = lthy2
   200     val ((_, def), lthy3) = lthy2
   176       |> Local_Theory.background_theory_result
   201       |> Local_Theory.background_theory_result
   177         (Thm.add_def (Proof_Context.defs_context lthy2) false false
   202         (Thm.add_def (Proof_Context.defs_context lthy2) false false
   178           (Thm.def_binding_optional b b_def, Logic.mk_equals (lhs, rhs)));
   203           (Thm.def_binding_optional b b_def, Logic.mk_equals (lhs, rhs)))
       
   204       ||> foundation_interpretation (b, (const, target_params));
   179   in ((lhs, def), lthy3) end;
   205   in ((lhs, def), lthy3) end;
   180 
   206 
   181 fun background_declaration decl lthy =
   207 fun background_declaration decl lthy =
   182   let
   208   let
   183     fun theory_decl context =
   209     fun theory_decl context =