29 (string * thm list) list * local_theory |
29 (string * thm list) list * local_theory |
30 val abbrev: (Syntax.mode -> binding * mixfix -> term -> |
30 val abbrev: (Syntax.mode -> binding * mixfix -> term -> |
31 term list * term list -> local_theory -> local_theory) -> |
31 term list * term list -> local_theory -> local_theory) -> |
32 Syntax.mode -> (binding * mixfix) * term -> local_theory -> (term * term) * local_theory |
32 Syntax.mode -> (binding * mixfix) * term -> local_theory -> (term * term) * local_theory |
33 |
33 |
34 (*theory operations*) |
34 (*theory target primitives*) |
35 val theory_foundation: ((binding * typ) * mixfix) * (binding * term) -> |
35 val theory_target_foundation: ((binding * typ) * mixfix) * (binding * term) -> |
36 term list * term list -> local_theory -> (term * thm) * local_theory |
36 term list * term list -> local_theory -> (term * thm) * local_theory |
37 val theory_notes: string -> |
37 val theory_target_notes: string -> |
38 (Attrib.binding * (thm list * Token.src list) list) list -> |
38 (Attrib.binding * (thm list * Token.src list) list) list -> |
39 (Attrib.binding * (thm list * Token.src list) list) list -> |
39 (Attrib.binding * (thm list * Token.src list) list) list -> |
40 local_theory -> local_theory |
40 local_theory -> local_theory |
|
41 val theory_target_abbrev: Syntax.mode -> (binding * mixfix) -> term -> term list * term list -> |
|
42 local_theory -> local_theory |
|
43 |
|
44 (*theory target operations*) |
41 val theory_declaration: declaration -> local_theory -> local_theory |
45 val theory_declaration: declaration -> local_theory -> local_theory |
42 val theory_abbrev: Syntax.mode -> (binding * mixfix) -> term -> term list * term list -> |
|
43 local_theory -> local_theory |
|
44 val theory_registration: string * morphism -> (morphism * bool) option -> morphism -> |
46 val theory_registration: string * morphism -> (morphism * bool) option -> morphism -> |
45 local_theory -> local_theory |
47 local_theory -> local_theory |
46 |
48 |
47 (*locale operations*) |
49 (*locale target primitives*) |
48 val locale_notes: string -> string -> |
50 val locale_target_notes: string -> string -> |
49 (Attrib.binding * (thm list * Token.src list) list) list -> |
51 (Attrib.binding * (thm list * Token.src list) list) list -> |
50 (Attrib.binding * (thm list * Token.src list) list) list -> |
52 (Attrib.binding * (thm list * Token.src list) list) list -> |
51 local_theory -> local_theory |
53 local_theory -> local_theory |
52 val locale_target_declaration: string -> bool -> declaration -> local_theory -> local_theory |
54 val locale_target_declaration: string -> bool -> declaration -> local_theory -> local_theory |
53 val locale_declaration: string -> {syntax: bool, pervasive: bool} -> declaration -> |
|
54 local_theory -> local_theory |
|
55 val locale_target_const: string -> (morphism -> bool) -> Syntax.mode -> |
55 val locale_target_const: string -> (morphism -> bool) -> Syntax.mode -> |
56 (binding * mixfix) * term -> local_theory -> local_theory |
56 (binding * mixfix) * term -> local_theory -> local_theory |
|
57 |
|
58 (*locale operations*) |
|
59 val locale_declaration: string -> {syntax: bool, pervasive: bool} -> declaration -> |
|
60 local_theory -> local_theory |
57 val locale_const: string -> Syntax.mode -> (binding * mixfix) * term -> |
61 val locale_const: string -> Syntax.mode -> (binding * mixfix) * term -> |
58 local_theory -> local_theory |
62 local_theory -> local_theory |
59 val locale_dependency: string -> string * morphism -> (morphism * bool) option -> morphism -> |
63 val locale_dependency: string -> string * morphism -> (morphism * bool) option -> morphism -> |
60 local_theory -> local_theory |
64 local_theory -> local_theory |
61 end |
65 end |
257 |
261 |
258 in (result'', result) end; |
262 in (result'', result) end; |
259 |
263 |
260 in |
264 in |
261 |
265 |
262 fun notes notes' kind facts lthy = |
266 fun notes target_notes kind facts lthy = |
263 let |
267 let |
264 val facts' = facts |
268 val facts' = facts |
265 |> map (fn (a, bs) => (a, Global_Theory.burrow_fact (Global_Theory.name_multi |
269 |> map (fn (a, bs) => (a, Global_Theory.burrow_fact (Global_Theory.name_multi |
266 (Local_Theory.full_name lthy (fst a))) bs)) |
270 (Local_Theory.full_name lthy (fst a))) bs)) |
267 |> Global_Theory.map_facts (import_export_proof lthy); |
271 |> Global_Theory.map_facts (import_export_proof lthy); |
268 val local_facts = Global_Theory.map_facts #1 facts'; |
272 val local_facts = Global_Theory.map_facts #1 facts'; |
269 val global_facts = Global_Theory.map_facts #2 facts'; |
273 val global_facts = Global_Theory.map_facts #2 facts'; |
270 in |
274 in |
271 lthy |
275 lthy |
272 |> notes' kind global_facts (Attrib.partial_evaluation lthy local_facts) |
276 |> target_notes kind global_facts (Attrib.partial_evaluation lthy local_facts) |
273 |> Attrib.local_notes kind local_facts |
277 |> Attrib.local_notes kind local_facts |
274 end; |
278 end; |
275 |
279 |
276 end; |
280 end; |
277 |
281 |
278 |
282 |
279 (* abbrev *) |
283 (* abbrev *) |
280 |
284 |
281 fun abbrev abbrev' prmode ((b, mx), rhs) lthy = |
285 fun abbrev target_abbrev prmode ((b, mx), rhs) lthy = |
282 let |
286 let |
283 val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy); |
287 val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy); |
284 |
288 |
285 val rhs' = Assumption.export_term lthy (Local_Theory.target_of lthy) rhs; |
289 val rhs' = Assumption.export_term lthy (Local_Theory.target_of lthy) rhs; |
286 val term_params = map Free (sort (Variable.fixed_ord lthy o apply2 #1) (Variable.add_fixed lthy rhs' [])); |
290 val term_params = map Free (sort (Variable.fixed_ord lthy o apply2 #1) (Variable.add_fixed lthy rhs' [])); |
291 subtract (op =) (Term.add_tfreesT (Term.fastype_of u) []) (Term.add_tfrees u []); |
295 subtract (op =) (Term.add_tfreesT (Term.fastype_of u) []) (Term.add_tfrees u []); |
292 val mx' = check_mixfix lthy (b, extra_tfrees) mx; |
296 val mx' = check_mixfix lthy (b, extra_tfrees) mx; |
293 val type_params = map (Logic.mk_type o TFree) extra_tfrees; |
297 val type_params = map (Logic.mk_type o TFree) extra_tfrees; |
294 in |
298 in |
295 lthy |
299 lthy |
296 |> abbrev' prmode (b, mx') global_rhs (type_params, term_params) |
300 |> target_abbrev prmode (b, mx') global_rhs (type_params, term_params) |
297 |> Proof_Context.add_abbrev Print_Mode.internal (b, rhs) |> snd |
301 |> Proof_Context.add_abbrev Print_Mode.internal (b, rhs) |> snd |
298 |> Local_Defs.fixed_abbrev ((b, NoSyn), rhs) |
302 |> Local_Defs.fixed_abbrev ((b, NoSyn), rhs) |
299 end; |
303 end; |
300 |
304 |
301 |
305 |
302 |
306 |
303 (** theory operations **) |
307 (** theory target primitives **) |
304 |
308 |
305 fun theory_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) = |
309 fun theory_target_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) = |
306 background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) |
310 background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) |
307 #-> (fn (lhs, def) => standard_const (op <>) Syntax.mode_default ((b, mx), lhs) |
311 #-> (fn (lhs, def) => standard_const (op <>) Syntax.mode_default ((b, mx), lhs) |
308 #> pair (lhs, def)); |
312 #> pair (lhs, def)); |
309 |
313 |
310 fun theory_notes kind global_facts local_facts = |
314 fun theory_target_notes kind global_facts local_facts = |
311 Local_Theory.background_theory (Attrib.global_notes kind global_facts #> snd) |
315 Local_Theory.background_theory (Attrib.global_notes kind global_facts #> snd) |
312 #> standard_notes (op <>) kind local_facts; |
316 #> standard_notes (op <>) kind local_facts; |
313 |
317 |
314 fun theory_declaration decl = |
318 fun theory_target_abbrev prmode (b, mx) global_rhs params = |
315 background_declaration decl #> standard_declaration (K true) decl; |
|
316 |
|
317 fun theory_abbrev prmode (b, mx) global_rhs params = |
|
318 Local_Theory.background_theory_result |
319 Local_Theory.background_theory_result |
319 (Sign.add_abbrev (#1 prmode) (b, global_rhs) #-> |
320 (Sign.add_abbrev (#1 prmode) (b, global_rhs) #-> |
320 (fn (lhs, _) => (* FIXME type_params!? *) |
321 (fn (lhs, _) => (* FIXME type_params!? *) |
321 Sign.notation true prmode [(lhs, check_mixfix_global (b, null (snd params)) mx)] #> pair lhs)) |
322 Sign.notation true prmode [(lhs, check_mixfix_global (b, null (snd params)) mx)] #> pair lhs)) |
322 #-> (fn lhs => standard_const (op <>) prmode |
323 #-> (fn lhs => standard_const (op <>) prmode |
323 ((b, if null (snd params) then NoSyn else mx), Term.list_comb (Logic.unvarify_global lhs, snd params))); |
324 ((b, if null (snd params) then NoSyn else mx), Term.list_comb (Logic.unvarify_global lhs, snd params))); |
324 |
325 |
|
326 |
|
327 (** theory operations **) |
|
328 |
|
329 fun theory_declaration decl = |
|
330 background_declaration decl #> standard_declaration (K true) decl; |
|
331 |
325 val theory_registration = |
332 val theory_registration = |
326 Local_Theory.raw_theory o Context.theory_map ooo Locale.add_registration; |
333 Local_Theory.raw_theory o Context.theory_map ooo Locale.add_registration; |
327 |
334 |
328 |
335 |
329 |
336 |
330 (** locale operations **) |
337 (** locale target primitives **) |
331 |
338 |
332 fun locale_notes locale kind global_facts local_facts = |
339 fun locale_target_notes locale kind global_facts local_facts = |
333 Local_Theory.background_theory |
340 Local_Theory.background_theory |
334 (Attrib.global_notes kind (Attrib.map_facts (K []) global_facts) #> snd) #> |
341 (Attrib.global_notes kind (Attrib.map_facts (K []) global_facts) #> snd) #> |
335 (fn lthy => lthy |> |
342 (fn lthy => lthy |> |
336 Local_Theory.target (fn ctxt => ctxt |> |
343 Local_Theory.target (fn ctxt => ctxt |> |
337 Locale.add_thmss locale kind (standard_facts lthy ctxt local_facts))) #> |
344 Locale.add_thmss locale kind (standard_facts lthy ctxt local_facts))) #> |
340 fun locale_target_declaration locale syntax decl lthy = lthy |
347 fun locale_target_declaration locale syntax decl lthy = lthy |
341 |> Local_Theory.target (fn ctxt => ctxt |> |
348 |> Local_Theory.target (fn ctxt => ctxt |> |
342 Locale.add_declaration locale syntax |
349 Locale.add_declaration locale syntax |
343 (Morphism.transform (Local_Theory.standard_morphism lthy ctxt) decl)); |
350 (Morphism.transform (Local_Theory.standard_morphism lthy ctxt) decl)); |
344 |
351 |
|
352 fun locale_target_const locale phi_pred prmode ((b, mx), rhs) = |
|
353 locale_target_declaration locale true (const_decl phi_pred prmode ((b, mx), rhs)) |
|
354 |
|
355 |
|
356 (** locale operations **) |
|
357 |
345 fun locale_declaration locale {syntax, pervasive} decl = |
358 fun locale_declaration locale {syntax, pervasive} decl = |
346 pervasive ? background_declaration decl |
359 pervasive ? background_declaration decl |
347 #> locale_target_declaration locale syntax decl |
360 #> locale_target_declaration locale syntax decl |
348 #> standard_declaration (fn (_, other) => other <> 0) decl; |
361 #> standard_declaration (fn (_, other) => other <> 0) decl; |
349 |
362 |
350 fun locale_target_const locale phi_pred prmode ((b, mx), rhs) = |
|
351 locale_target_declaration locale true (const_decl phi_pred prmode ((b, mx), rhs)) |
|
352 |
|
353 fun locale_const locale prmode ((b, mx), rhs) = |
363 fun locale_const locale prmode ((b, mx), rhs) = |
354 locale_target_const locale (K true) prmode ((b, mx), rhs) |
364 locale_target_const locale (K true) prmode ((b, mx), rhs) |
355 #> standard_const (fn (this, other) => other <> 0 andalso this <> other) prmode ((b, mx), rhs); |
365 #> standard_const (fn (this, other) => other <> 0 andalso this <> other) prmode ((b, mx), rhs); |
356 |
366 |
357 fun locale_dependency locale dep_morph mixin export = |
367 fun locale_dependency locale dep_morph mixin export = |