19 val read_classrel: theory -> xstring * xstring -> class * class |
19 val read_classrel: theory -> xstring * xstring -> class * class |
20 val add_classrel: thm -> theory -> theory |
20 val add_classrel: thm -> theory -> theory |
21 val add_arity: thm -> theory -> theory |
21 val add_arity: thm -> theory -> theory |
22 val prove_classrel: class * class -> tactic -> theory -> theory |
22 val prove_classrel: class * class -> tactic -> theory -> theory |
23 val prove_arity: string * sort list * sort -> tactic -> theory -> theory |
23 val prove_arity: string * sort list * sort -> tactic -> theory -> theory |
24 val define_class: bstring * xstring list -> string list -> |
24 val define_class: bstring * class list -> string list -> |
25 ((bstring * Attrib.src list) * string list) list -> theory -> class * theory |
|
26 val define_class_i: bstring * class list -> string list -> |
|
27 ((bstring * attribute list) * term list) list -> theory -> class * theory |
25 ((bstring * attribute list) * term list) list -> theory -> class * theory |
28 val read_param: theory -> string -> string |
|
29 val axiomatize_class: bstring * xstring list -> theory -> theory |
26 val axiomatize_class: bstring * xstring list -> theory -> theory |
30 val axiomatize_class_i: bstring * class list -> theory -> theory |
27 val axiomatize_class_i: bstring * class list -> theory -> theory |
31 val axiomatize_classrel: (xstring * xstring) list -> theory -> theory |
28 val axiomatize_classrel: (xstring * xstring) list -> theory -> theory |
32 val axiomatize_classrel_i: (class * class) list -> theory -> theory |
29 val axiomatize_classrel_i: (class * class) list -> theory -> theory |
33 val axiomatize_arity: xstring * string list * string -> theory -> theory |
30 val axiomatize_arity: xstring * string list * string -> theory -> theory |
268 |
265 |
269 |
266 |
270 |
267 |
271 (** class definitions **) |
268 (** class definitions **) |
272 |
269 |
273 fun read_param thy raw_t = |
270 fun define_class (bclass, raw_super) params raw_specs thy = |
274 let |
|
275 val t = Sign.read_term thy raw_t |
|
276 in case try dest_Const t |
|
277 of SOME (c, _) => c |
|
278 | NONE => error ("Not a constant: " ^ Sign.string_of_term thy t) |
|
279 end; |
|
280 |
|
281 local |
|
282 |
|
283 fun def_class prep_class prep_att prep_param prep_propp |
|
284 (bclass, raw_super) raw_params raw_specs thy = |
|
285 let |
271 let |
286 val ctxt = ProofContext.init thy; |
272 val ctxt = ProofContext.init thy; |
287 val pp = ProofContext.pp ctxt; |
273 val pp = ProofContext.pp ctxt; |
288 |
274 |
289 |
275 |
290 (* prepare specification *) |
276 (* prepare specification *) |
291 |
277 |
292 val bconst = Logic.const_of_class bclass; |
278 val bconst = Logic.const_of_class bclass; |
293 val class = Sign.full_name thy bclass; |
279 val class = Sign.full_name thy bclass; |
294 val super = map (prep_class thy) raw_super |> Sign.certify_sort thy; |
280 val super = Sign.certify_sort thy raw_super; |
295 |
281 |
296 fun prep_axiom t = |
282 fun prep_axiom t = |
297 (case Term.add_tfrees t [] of |
283 (case Term.add_tfrees t [] of |
298 [(a, S)] => |
284 [(a, S)] => |
299 if Sign.subsort thy (super, S) then t |
285 if Sign.subsort thy (super, S) then t |
303 | [] => t |
289 | [] => t |
304 | _ => error ("Multiple type variables in class axiom:\n" ^ Pretty.string_of_term pp t)) |
290 | _ => error ("Multiple type variables in class axiom:\n" ^ Pretty.string_of_term pp t)) |
305 |> map_types (Term.map_atyps (fn TFree _ => Term.aT [] | U => U)) |
291 |> map_types (Term.map_atyps (fn TFree _ => Term.aT [] | U => U)) |
306 |> Logic.close_form; |
292 |> Logic.close_form; |
307 |
293 |
308 val axiomss = prep_propp (ctxt, map (map (rpair []) o snd) raw_specs) |
294 (*FIXME is ProofContext.cert_propp really neccessary?*) |
|
295 val axiomss = ProofContext.cert_propp (ctxt, map (map (rpair []) o snd) raw_specs) |
309 |> snd |> map (map (prep_axiom o fst)); |
296 |> snd |> map (map (prep_axiom o fst)); |
310 val name_atts = Attrib.map_specs (prep_att thy) raw_specs |> map fst; |
297 val name_atts = map fst raw_specs; |
311 |
298 |
312 |
299 |
313 (* definition *) |
300 (* definition *) |
314 |
301 |
315 val conjs = map (curry Logic.mk_inclass (Term.aT [])) super @ flat axiomss; |
302 val conjs = map (curry Logic.mk_inclass (Term.aT [])) super @ flat axiomss; |
334 ((superN, []), [(map Drule.standard raw_classrel, [])]), |
321 ((superN, []), [(map Drule.standard raw_classrel, [])]), |
335 ((axiomsN, []), [(map (fn th => Drule.standard (class_triv RS th)) raw_axioms, [])])]; |
322 ((axiomsN, []), [(map (fn th => Drule.standard (class_triv RS th)) raw_axioms, [])])]; |
336 |
323 |
337 (* params *) |
324 (* params *) |
338 |
325 |
339 val params = map (prep_param thy) raw_params; |
|
340 val params_typs = map (fn param => |
326 val params_typs = map (fn param => |
341 let |
327 let |
342 val ty = Sign.the_const_type thy param; |
328 val ty = Sign.the_const_type thy param; |
343 val _ = case Term.typ_tvars ty |
329 val _ = case Term.typ_tvars ty |
344 of [_] => () |
330 of [_] => () |
358 |> map_axclasses (fn (axclasses, parameters) => |
344 |> map_axclasses (fn (axclasses, parameters) => |
359 (Symtab.update (class, axclass) axclasses, |
345 (Symtab.update (class, axclass) axclasses, |
360 fold (fn x => add_param pp (x, class)) params parameters)); |
346 fold (fn x => add_param pp (x, class)) params parameters)); |
361 |
347 |
362 in (class, result_thy) end; |
348 in (class, result_thy) end; |
363 |
|
364 in |
|
365 |
|
366 val define_class = def_class Sign.read_class Attrib.attribute read_param ProofContext.read_propp; |
|
367 val define_class_i = def_class Sign.certify_class (K I) (K I) ProofContext.cert_propp; |
|
368 |
|
369 end; |
|
370 |
349 |
371 |
350 |
372 |
351 |
373 (** axiomatizations **) |
352 (** axiomatizations **) |
374 |
353 |