29361
|
1 |
(* Title: Pure/Isar/locale.ML
|
|
2 |
Author: Clemens Ballarin, TU Muenchen
|
|
3 |
|
|
4 |
Locales -- Isar proof contexts as meta-level predicates, with local
|
|
5 |
syntax and implicit structures.
|
|
6 |
|
|
7 |
Draws basic ideas from Florian Kammueller's original version of
|
|
8 |
locales, but uses the richer infrastructure of Isar instead of the raw
|
|
9 |
meta-logic. Furthermore, structured import of contexts (with merge
|
|
10 |
and rename operations) are provided, as well as type-inference of the
|
|
11 |
signature parts, and predicate definitions of the specification text.
|
|
12 |
|
|
13 |
Interpretation enables the reuse of theorems of locales in other
|
|
14 |
contexts, namely those defined by theories, structured proofs and
|
|
15 |
locales themselves.
|
|
16 |
|
|
17 |
See also:
|
|
18 |
|
|
19 |
[1] Clemens Ballarin. Locales and Locale Expressions in Isabelle/Isar.
|
|
20 |
In Stefano Berardi et al., Types for Proofs and Programs: International
|
|
21 |
Workshop, TYPES 2003, Torino, Italy, LNCS 3085, pages 34-50, 2004.
|
|
22 |
[2] Clemens Ballarin. Interpretation of Locales in Isabelle: Managing
|
|
23 |
Dependencies between Locales. Technical Report TUM-I0607, Technische
|
|
24 |
Universitaet Muenchen, 2006.
|
|
25 |
[3] Clemens Ballarin. Interpretation of Locales in Isabelle: Theories and
|
|
26 |
Proof Contexts. In J.M. Borwein and W.M. Farmer, MKM 2006, LNAI 4108,
|
|
27 |
pages 31-43, 2006.
|
|
28 |
*)
|
|
29 |
|
|
30 |
signature LOCALE =
|
|
31 |
sig
|
|
32 |
type locale
|
|
33 |
|
|
34 |
val register_locale: bstring ->
|
|
35 |
(string * sort) list * (Binding.T * typ option * mixfix) list ->
|
|
36 |
term option * term list ->
|
29441
|
37 |
thm option * thm option -> thm list ->
|
29361
|
38 |
(declaration * stamp) list * (declaration * stamp) list ->
|
|
39 |
((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list ->
|
|
40 |
((string * Morphism.morphism) * stamp) list -> theory -> theory
|
|
41 |
|
|
42 |
(* Locale name space *)
|
|
43 |
val intern: theory -> xstring -> string
|
|
44 |
val extern: theory -> string -> xstring
|
|
45 |
|
|
46 |
(* Specification *)
|
29392
|
47 |
val defined: theory -> string -> bool
|
29361
|
48 |
val params_of: theory -> string -> (Binding.T * typ option * mixfix) list
|
29441
|
49 |
val intros_of: theory -> string -> thm option * thm option
|
|
50 |
val axioms_of: theory -> string -> thm list
|
29361
|
51 |
val instance_of: theory -> string -> Morphism.morphism -> term list
|
|
52 |
val specification_of: theory -> string -> term option * term list
|
|
53 |
val declarations_of: theory -> string -> declaration list * declaration list
|
|
54 |
|
|
55 |
(* Storing results *)
|
|
56 |
val add_thmss: string -> string -> (Attrib.binding * (thm list * Attrib.src list) list) list ->
|
|
57 |
Proof.context -> Proof.context
|
|
58 |
val add_type_syntax: string -> declaration -> Proof.context -> Proof.context
|
|
59 |
val add_term_syntax: string -> declaration -> Proof.context -> Proof.context
|
|
60 |
val add_declaration: string -> declaration -> Proof.context -> Proof.context
|
|
61 |
val add_dependency: string -> (string * Morphism.morphism) -> theory -> theory
|
|
62 |
|
|
63 |
(* Activation *)
|
|
64 |
val activate_declarations: theory -> string * Morphism.morphism ->
|
|
65 |
Proof.context -> Proof.context
|
|
66 |
val activate_global_facts: string * Morphism.morphism -> theory -> theory
|
|
67 |
val activate_local_facts: string * Morphism.morphism -> Proof.context -> Proof.context
|
|
68 |
val init: string -> theory -> Proof.context
|
|
69 |
|
|
70 |
(* Reasoning about locales *)
|
|
71 |
val witness_attrib: attribute
|
|
72 |
val intro_attrib: attribute
|
|
73 |
val unfold_attrib: attribute
|
|
74 |
val intro_locales_tac: bool -> Proof.context -> thm list -> tactic
|
|
75 |
|
|
76 |
(* Registrations *)
|
29392
|
77 |
val add_registration: (string * (Morphism.morphism * Morphism.morphism)) ->
|
29361
|
78 |
theory -> theory
|
29392
|
79 |
val amend_registration: Morphism.morphism -> (string * Morphism.morphism) ->
|
29361
|
80 |
theory -> theory
|
29392
|
81 |
val get_registrations: theory -> (string * Morphism.morphism) list
|
29361
|
82 |
|
|
83 |
(* Diagnostic *)
|
|
84 |
val print_locales: theory -> unit
|
|
85 |
val print_locale: theory -> bool -> bstring -> unit
|
|
86 |
end;
|
|
87 |
|
|
88 |
|
|
89 |
(*** Theorem list extensible via attribute --- to control intro_locales_tac ***)
|
|
90 |
|
|
91 |
(* FIXME: consider moving named_thms.ML up in the build hierarchy and using that *)
|
|
92 |
functor ThmsFun() =
|
|
93 |
struct
|
|
94 |
|
|
95 |
structure Data = GenericDataFun
|
|
96 |
(
|
|
97 |
type T = thm list;
|
|
98 |
val empty = [];
|
|
99 |
val extend = I;
|
|
100 |
fun merge _ = Thm.merge_thms;
|
|
101 |
);
|
|
102 |
|
|
103 |
val get = Data.get o Context.Proof;
|
|
104 |
val add = Thm.declaration_attribute (Data.map o Thm.add_thm);
|
|
105 |
|
|
106 |
end;
|
|
107 |
|
|
108 |
|
|
109 |
structure Locale: LOCALE =
|
|
110 |
struct
|
|
111 |
|
|
112 |
datatype ctxt = datatype Element.ctxt;
|
|
113 |
|
|
114 |
|
29392
|
115 |
|
|
116 |
(*** Theory data ***)
|
29361
|
117 |
|
|
118 |
datatype locale = Loc of {
|
29392
|
119 |
(** static part **)
|
29361
|
120 |
parameters: (string * sort) list * (Binding.T * typ option * mixfix) list,
|
|
121 |
(* type and term parameters *)
|
|
122 |
spec: term option * term list,
|
|
123 |
(* assumptions (as a single predicate expression) and defines *)
|
29441
|
124 |
intros: thm option * thm option,
|
|
125 |
axioms: thm list,
|
29392
|
126 |
(** dynamic part **)
|
29361
|
127 |
decls: (declaration * stamp) list * (declaration * stamp) list,
|
|
128 |
(* type and term syntax declarations *)
|
|
129 |
notes: ((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list,
|
|
130 |
(* theorem declarations *)
|
|
131 |
dependencies: ((string * Morphism.morphism) * stamp) list
|
|
132 |
(* locale dependencies (sublocale relation) *)
|
29392
|
133 |
};
|
29361
|
134 |
|
29441
|
135 |
fun mk_locale ((parameters, spec, intros, axioms), ((decls, notes), dependencies)) =
|
|
136 |
Loc {parameters = parameters, intros = intros, axioms = axioms, spec = spec,
|
|
137 |
decls = decls, notes = notes, dependencies = dependencies};
|
|
138 |
fun map_locale f (Loc {parameters, spec, intros, axioms, decls, notes, dependencies}) =
|
|
139 |
mk_locale (f ((parameters, spec, intros, axioms), ((decls, notes), dependencies)));
|
|
140 |
fun merge_locale (Loc {parameters, spec, intros, axioms, decls = (decls1, decls2),
|
|
141 |
notes, dependencies}, Loc {decls = (decls1', decls2'), notes = notes',
|
|
142 |
dependencies = dependencies', ...}) = mk_locale
|
|
143 |
((parameters, spec, intros, axioms),
|
|
144 |
(((merge (eq_snd op =) (decls1, decls1'), merge (eq_snd op =) (decls2, decls2')),
|
|
145 |
merge (eq_snd op =) (notes, notes')),
|
|
146 |
merge (eq_snd op =) (dependencies, dependencies')));
|
29361
|
147 |
|
|
148 |
structure LocalesData = TheoryDataFun
|
|
149 |
(
|
29392
|
150 |
type T = locale NameSpace.table;
|
29361
|
151 |
val empty = NameSpace.empty_table;
|
|
152 |
val copy = I;
|
|
153 |
val extend = I;
|
29392
|
154 |
fun merge _ = NameSpace.join_tables (K merge_locale);
|
29361
|
155 |
);
|
|
156 |
|
|
157 |
val intern = NameSpace.intern o #1 o LocalesData.get;
|
|
158 |
val extern = NameSpace.extern o #1 o LocalesData.get;
|
|
159 |
|
29392
|
160 |
fun get_locale thy = Symtab.lookup (#2 (LocalesData.get thy));
|
|
161 |
|
|
162 |
fun defined thy = is_some o get_locale thy;
|
29361
|
163 |
|
|
164 |
fun the_locale thy name = case get_locale thy name
|
29392
|
165 |
of SOME (Loc loc) => loc
|
29361
|
166 |
| NONE => error ("Unknown locale " ^ quote name);
|
|
167 |
|
29441
|
168 |
fun register_locale bname parameters spec intros axioms decls notes dependencies thy =
|
29361
|
169 |
thy |> LocalesData.map (NameSpace.bind (Sign.naming_of thy) (Binding.name bname,
|
29441
|
170 |
mk_locale ((parameters, spec, intros, axioms), ((decls, notes), dependencies))) #> snd);
|
29361
|
171 |
|
29392
|
172 |
fun change_locale name =
|
|
173 |
LocalesData.map o apsnd o Symtab.map_entry name o map_locale o apsnd;
|
29361
|
174 |
|
|
175 |
fun print_locales thy =
|
29392
|
176 |
Pretty.strs ("locales:" :: map #1 (NameSpace.extern_table (LocalesData.get thy)))
|
|
177 |
|> Pretty.writeln;
|
29361
|
178 |
|
|
179 |
|
|
180 |
(*** Primitive operations ***)
|
|
181 |
|
29392
|
182 |
fun params_of thy = snd o #parameters o the_locale thy;
|
29361
|
183 |
|
29441
|
184 |
fun intros_of thy = #intros o the_locale thy;
|
|
185 |
|
|
186 |
fun axioms_of thy = #axioms o the_locale thy;
|
|
187 |
|
29392
|
188 |
fun instance_of thy name morph = params_of thy name |>
|
|
189 |
map ((fn (b, T, _) => Free (Binding.base_name b, the T)) #> Morphism.term morph);
|
29361
|
190 |
|
29392
|
191 |
fun specification_of thy = #spec o the_locale thy;
|
29361
|
192 |
|
29392
|
193 |
fun declarations_of thy name = the_locale thy name |>
|
|
194 |
#decls |> apfst (map fst) |> apsnd (map fst);
|
29361
|
195 |
|
|
196 |
|
|
197 |
(*** Activate context elements of locale ***)
|
|
198 |
|
|
199 |
(** Identifiers: activated locales in theory or proof context **)
|
|
200 |
|
|
201 |
type identifiers = (string * term list) list;
|
|
202 |
|
|
203 |
val empty = ([] : identifiers);
|
|
204 |
|
|
205 |
fun ident_eq thy ((n: string, ts), (m, ss)) = (m = n) andalso Pattern.matchess thy (ss, ts);
|
|
206 |
|
|
207 |
local
|
|
208 |
|
|
209 |
datatype 'a delayed = Ready of 'a | ToDo of ('a delayed * 'a delayed);
|
|
210 |
|
|
211 |
structure IdentifiersData = GenericDataFun
|
|
212 |
(
|
|
213 |
type T = identifiers delayed;
|
|
214 |
val empty = Ready empty;
|
|
215 |
val extend = I;
|
|
216 |
fun merge _ = ToDo;
|
|
217 |
);
|
|
218 |
|
|
219 |
in
|
|
220 |
|
|
221 |
fun finish thy (ToDo (i1, i2)) = merge (ident_eq thy) (finish thy i1, finish thy i2)
|
|
222 |
| finish _ (Ready ids) = ids;
|
|
223 |
|
|
224 |
val _ = Context.>> (Context.map_theory (Theory.at_begin (fn thy =>
|
|
225 |
(case IdentifiersData.get (Context.Theory thy) of
|
|
226 |
Ready _ => NONE |
|
|
227 |
ids => SOME (Context.theory_map (IdentifiersData.put (Ready (finish thy ids))) thy))
|
|
228 |
)));
|
|
229 |
|
|
230 |
fun get_global_idents thy =
|
|
231 |
let val (Ready ids) = (IdentifiersData.get o Context.Theory) thy in ids end;
|
|
232 |
val put_global_idents = Context.theory_map o IdentifiersData.put o Ready;
|
|
233 |
|
|
234 |
fun get_local_idents ctxt =
|
|
235 |
let val (Ready ids) = (IdentifiersData.get o Context.Proof) ctxt in ids end;
|
|
236 |
val put_local_idents = Context.proof_map o IdentifiersData.put o Ready;
|
|
237 |
|
|
238 |
end;
|
|
239 |
|
|
240 |
|
|
241 |
(** Resolve locale dependencies in a depth-first fashion **)
|
|
242 |
|
|
243 |
local
|
|
244 |
|
|
245 |
val roundup_bound = 120;
|
|
246 |
|
|
247 |
fun add thy depth (name, morph) (deps, marked) =
|
|
248 |
if depth > roundup_bound
|
|
249 |
then error "Roundup bound exceeded (sublocale relation probably not terminating)."
|
|
250 |
else
|
|
251 |
let
|
29392
|
252 |
val {parameters = (_, params), dependencies, ...} = the_locale thy name;
|
29361
|
253 |
val instance = instance_of thy name morph;
|
|
254 |
in
|
|
255 |
if member (ident_eq thy) marked (name, instance)
|
|
256 |
then (deps, marked)
|
|
257 |
else
|
|
258 |
let
|
|
259 |
val dependencies' =
|
|
260 |
map (fn ((name, morph'), _) => (name, morph' $> morph)) dependencies;
|
|
261 |
val marked' = (name, instance) :: marked;
|
|
262 |
val (deps', marked'') = fold_rev (add thy (depth + 1)) dependencies' ([], marked');
|
|
263 |
in
|
|
264 |
((name, morph) :: deps' @ deps, marked'')
|
|
265 |
end
|
|
266 |
end;
|
|
267 |
|
|
268 |
in
|
|
269 |
|
|
270 |
fun roundup thy activate_dep (name, morph) (marked, input) =
|
|
271 |
let
|
|
272 |
(* Find all dependencies incuding new ones (which are dependencies enriching
|
|
273 |
existing registrations). *)
|
|
274 |
val (dependencies, marked') = add thy 0 (name, morph) ([], empty);
|
|
275 |
(* Filter out exisiting fragments. *)
|
|
276 |
val dependencies' = filter_out (fn (name, morph) =>
|
|
277 |
member (ident_eq thy) marked (name, instance_of thy name morph)) dependencies;
|
|
278 |
in
|
|
279 |
(merge (ident_eq thy) (marked, marked'), input |> fold_rev (activate_dep thy) dependencies')
|
|
280 |
end;
|
|
281 |
|
|
282 |
end;
|
|
283 |
|
|
284 |
|
|
285 |
(* Declarations, facts and entire locale content *)
|
|
286 |
|
|
287 |
fun activate_decls thy (name, morph) ctxt =
|
|
288 |
let
|
29392
|
289 |
val {decls = (typ_decls, term_decls), ...} = the_locale thy name;
|
29361
|
290 |
in
|
|
291 |
ctxt |> fold_rev (fn (decl, _) => Context.proof_map (decl morph)) typ_decls |>
|
|
292 |
fold_rev (fn (decl, _) => Context.proof_map (decl morph)) term_decls
|
|
293 |
end;
|
|
294 |
|
|
295 |
fun activate_notes activ_elem transfer thy (name, morph) input =
|
|
296 |
let
|
29392
|
297 |
val {notes, ...} = the_locale thy name;
|
29361
|
298 |
fun activate ((kind, facts), _) input =
|
|
299 |
let
|
|
300 |
val facts' = facts |> Element.facts_map (Element.morph_ctxt (transfer input $> morph))
|
|
301 |
in activ_elem (Notes (kind, facts')) input end;
|
|
302 |
in
|
|
303 |
fold_rev activate notes input
|
|
304 |
end;
|
|
305 |
|
|
306 |
fun activate_all name thy activ_elem transfer (marked, input) =
|
|
307 |
let
|
29392
|
308 |
val {parameters = (_, params), spec = (asm, defs), ...} =
|
29361
|
309 |
the_locale thy name;
|
|
310 |
in
|
|
311 |
input |>
|
|
312 |
(if not (null params) then activ_elem (Fixes params) else I) |>
|
|
313 |
(* FIXME type parameters *)
|
|
314 |
(if is_some asm then activ_elem (Assumes [(Attrib.empty_binding, [(the asm, [])])]) else I) |>
|
|
315 |
(if not (null defs)
|
|
316 |
then activ_elem (Defines (map (fn def => (Attrib.empty_binding, (def, []))) defs))
|
|
317 |
else I) |>
|
|
318 |
pair marked |> roundup thy (activate_notes activ_elem transfer) (name, Morphism.identity)
|
|
319 |
end;
|
|
320 |
|
|
321 |
|
|
322 |
(** Public activation functions **)
|
|
323 |
|
|
324 |
local
|
|
325 |
|
|
326 |
fun init_global_elem (Notes (kind, facts)) thy =
|
29392
|
327 |
let
|
|
328 |
val facts' = Attrib.map_facts (Attrib.attribute_i thy) facts
|
|
329 |
in Old_Locale.global_note_qualified kind facts' thy |> snd end
|
29361
|
330 |
|
|
331 |
fun init_local_elem (Fixes fixes) ctxt = ctxt |>
|
|
332 |
ProofContext.add_fixes_i fixes |> snd
|
|
333 |
| init_local_elem (Assumes assms) ctxt =
|
|
334 |
let
|
|
335 |
val assms' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) assms
|
|
336 |
in
|
|
337 |
ctxt |> fold Variable.auto_fixes (maps (map fst o snd) assms') |>
|
|
338 |
ProofContext.add_assms_i Assumption.assume_export assms' |> snd
|
|
339 |
end
|
|
340 |
| init_local_elem (Defines defs) ctxt =
|
|
341 |
let
|
|
342 |
val defs' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) defs
|
|
343 |
in
|
|
344 |
ctxt |> fold Variable.auto_fixes (map (fst o snd) defs') |>
|
|
345 |
ProofContext.add_assms_i LocalDefs.def_export (map (fn (attn, t) => (attn, [t])) defs') |>
|
|
346 |
snd
|
|
347 |
end
|
|
348 |
| init_local_elem (Notes (kind, facts)) ctxt =
|
|
349 |
let
|
|
350 |
val facts' = Attrib.map_facts (Attrib.attribute_i (ProofContext.theory_of ctxt)) facts
|
|
351 |
in Old_Locale.local_note_qualified kind facts' ctxt |> snd end
|
|
352 |
|
|
353 |
fun cons_elem false (Notes notes) elems = elems
|
|
354 |
| cons_elem _ elem elems = elem :: elems
|
|
355 |
|
|
356 |
in
|
|
357 |
|
|
358 |
fun activate_declarations thy dep ctxt =
|
|
359 |
roundup thy activate_decls dep (get_local_idents ctxt, ctxt) |> uncurry put_local_idents;
|
|
360 |
|
|
361 |
fun activate_global_facts dep thy =
|
|
362 |
roundup thy (activate_notes init_global_elem Element.transfer_morphism)
|
|
363 |
dep (get_global_idents thy, thy) |>
|
|
364 |
uncurry put_global_idents;
|
|
365 |
|
|
366 |
fun activate_local_facts dep ctxt =
|
|
367 |
roundup (ProofContext.theory_of ctxt)
|
|
368 |
(activate_notes init_local_elem (Element.transfer_morphism o ProofContext.theory_of)) dep
|
|
369 |
(get_local_idents ctxt, ctxt) |>
|
|
370 |
uncurry put_local_idents;
|
|
371 |
|
|
372 |
fun init name thy =
|
|
373 |
activate_all name thy init_local_elem (Element.transfer_morphism o ProofContext.theory_of)
|
|
374 |
(empty, ProofContext.init thy) |>
|
|
375 |
uncurry put_local_idents;
|
|
376 |
|
|
377 |
fun print_locale thy show_facts name =
|
|
378 |
let
|
|
379 |
val name' = intern thy name;
|
|
380 |
val ctxt = init name' thy
|
|
381 |
in
|
|
382 |
Pretty.big_list "locale elements:"
|
|
383 |
(activate_all name' thy (cons_elem show_facts) (K (Element.transfer_morphism thy))
|
|
384 |
(empty, []) |> snd |> rev |>
|
|
385 |
map (Element.pretty_ctxt ctxt) |> map Pretty.chunks) |> Pretty.writeln
|
|
386 |
end
|
|
387 |
|
|
388 |
end;
|
|
389 |
|
|
390 |
|
|
391 |
(*** Registrations: interpretations in theories ***)
|
|
392 |
|
29392
|
393 |
structure RegistrationsData = TheoryDataFun
|
29361
|
394 |
(
|
|
395 |
type T = ((string * (Morphism.morphism * Morphism.morphism)) * stamp) list;
|
29392
|
396 |
(* FIXME mixins need to be stamped *)
|
29361
|
397 |
(* registrations, in reverse order of declaration *)
|
|
398 |
val empty = [];
|
|
399 |
val extend = I;
|
29392
|
400 |
val copy = I;
|
29361
|
401 |
fun merge _ data : T = Library.merge (eq_snd op =) data;
|
|
402 |
(* FIXME consolidate with dependencies, consider one data slot only *)
|
|
403 |
);
|
|
404 |
|
29392
|
405 |
val get_registrations =
|
|
406 |
RegistrationsData.get #> map fst #> map (apsnd op $>);
|
29361
|
407 |
|
29392
|
408 |
fun add_registration (name, (base_morph, export)) thy =
|
|
409 |
roundup thy (fn _ => fn (name', morph') =>
|
|
410 |
(RegistrationsData.map o cons) ((name', (morph', export)), stamp ()))
|
29361
|
411 |
(name, base_morph) (get_global_idents thy, thy) |>
|
|
412 |
snd (* FIXME ?? uncurry put_global_idents *);
|
|
413 |
|
29392
|
414 |
fun amend_registration morph (name, base_morph) thy =
|
29361
|
415 |
let
|
29392
|
416 |
val regs = (RegistrationsData.get #> map fst) thy;
|
29361
|
417 |
val base = instance_of thy name base_morph;
|
|
418 |
fun match (name', (morph', _)) =
|
|
419 |
name = name' andalso eq_list (op aconv) (base, instance_of thy name' morph');
|
|
420 |
val i = find_index match (rev regs);
|
29392
|
421 |
val _ = if i = ~1 then error ("No registration of locale " ^
|
29361
|
422 |
quote (extern thy name) ^ " and parameter instantiation " ^
|
|
423 |
space_implode " " (map (quote o Syntax.string_of_term_global thy) base) ^ " available.")
|
|
424 |
else ();
|
|
425 |
in
|
29392
|
426 |
RegistrationsData.map (nth_map (length regs - 1 - i)
|
29361
|
427 |
(fn ((name, (base, export)), stamp) => ((name, (base $> morph, export)), stamp))) thy
|
|
428 |
end;
|
|
429 |
|
|
430 |
|
|
431 |
(*** Storing results ***)
|
|
432 |
|
|
433 |
(* Theorems *)
|
|
434 |
|
|
435 |
fun add_thmss loc kind args ctxt =
|
|
436 |
let
|
|
437 |
val ([Notes args'], ctxt') = Element.activate_i [Notes (kind, args)] ctxt;
|
|
438 |
val ctxt'' = ctxt' |> ProofContext.theory (
|
29392
|
439 |
(change_locale loc o apfst o apsnd) (cons (args', stamp ()))
|
|
440 |
#>
|
29361
|
441 |
(* Registrations *)
|
|
442 |
(fn thy => fold_rev (fn (name, morph) =>
|
|
443 |
let
|
|
444 |
val args'' = snd args' |> Element.facts_map (Element.morph_ctxt morph) |>
|
|
445 |
Attrib.map_facts (Attrib.attribute_i thy)
|
|
446 |
in Old_Locale.global_note_qualified kind args'' #> snd end)
|
29392
|
447 |
(get_registrations thy |> filter (fn (name, _) => name = loc)) thy))
|
29361
|
448 |
in ctxt'' end;
|
|
449 |
|
|
450 |
|
|
451 |
(* Declarations *)
|
|
452 |
|
|
453 |
local
|
|
454 |
|
|
455 |
fun decl_attrib decl phi = Thm.declaration_attribute (K (decl phi));
|
|
456 |
|
|
457 |
fun add_decls add loc decl =
|
29392
|
458 |
ProofContext.theory ((change_locale loc o apfst o apfst) (add (decl, stamp ())))
|
|
459 |
#>
|
29361
|
460 |
add_thmss loc Thm.internalK
|
|
461 |
[((Binding.empty, [Attrib.internal (decl_attrib decl)]), [([Drule.dummy_thm], [])])];
|
|
462 |
|
|
463 |
in
|
|
464 |
|
|
465 |
val add_type_syntax = add_decls (apfst o cons);
|
|
466 |
val add_term_syntax = add_decls (apsnd o cons);
|
|
467 |
val add_declaration = add_decls (K I);
|
|
468 |
|
|
469 |
end;
|
|
470 |
|
|
471 |
(* Dependencies *)
|
|
472 |
|
29392
|
473 |
fun add_dependency loc dep = (change_locale loc o apsnd) (cons (dep, stamp ()));
|
29361
|
474 |
|
|
475 |
|
|
476 |
(*** Reasoning about locales ***)
|
|
477 |
|
|
478 |
(** Storage for witnesses, intro and unfold rules **)
|
|
479 |
|
|
480 |
structure Witnesses = ThmsFun();
|
|
481 |
structure Intros = ThmsFun();
|
|
482 |
structure Unfolds = ThmsFun();
|
|
483 |
|
|
484 |
val witness_attrib = Witnesses.add;
|
|
485 |
val intro_attrib = Intros.add;
|
|
486 |
val unfold_attrib = Unfolds.add;
|
|
487 |
|
|
488 |
(** Tactic **)
|
|
489 |
|
|
490 |
fun intro_locales_tac eager ctxt facts st =
|
|
491 |
Method.intros_tac
|
|
492 |
(Witnesses.get ctxt @ Intros.get ctxt @ (if eager then Unfolds.get ctxt else [])) facts st;
|
|
493 |
|
|
494 |
val _ = Context.>> (Context.map_theory
|
|
495 |
(Method.add_methods
|
|
496 |
[("intro_locales",
|
|
497 |
Method.ctxt_args (fn ctxt => Method.METHOD (intro_locales_tac false ctxt ORELSE'
|
|
498 |
Old_Locale.intro_locales_tac false ctxt)),
|
|
499 |
"back-chain introduction rules of locales without unfolding predicates"),
|
|
500 |
("unfold_locales",
|
|
501 |
Method.ctxt_args (fn ctxt => Method.METHOD (intro_locales_tac true ctxt ORELSE'
|
|
502 |
Old_Locale.intro_locales_tac true ctxt)),
|
|
503 |
"back-chain all introduction rules of locales")]));
|
|
504 |
|
|
505 |
end;
|
|
506 |
|