src/Pure/Isar/specification.ML
author wenzelm
Tue Jan 24 00:43:34 2006 +0100 (2006-01-24)
changeset 18771 63efe00371af
parent 18728 6790126ab5f6
child 18786 591a37d48794
permissions -rw-r--r--
renamed axiomatize(_i) to axiomatization(_i);
LocalTheory;
wenzelm@18620
     1
(*  Title:      Pure/Isar/specification.ML
wenzelm@18620
     2
    ID:         $Id$
wenzelm@18620
     3
    Author:     Makarius
wenzelm@18620
     4
wenzelm@18771
     5
Common theory/locale specifications --- with type-inference, but
wenzelm@18771
     6
without internal polymorphism.
wenzelm@18620
     7
*)
wenzelm@18620
     8
wenzelm@18620
     9
signature SPECIFICATION =
wenzelm@18620
    10
sig
wenzelm@18771
    11
  val read_specification: (string * string option * mixfix) list ->
wenzelm@18771
    12
    ((string * Attrib.src list) * string list) list -> Proof.context ->
wenzelm@18771
    13
    (((string * typ) * mixfix) list * ((string * Attrib.src list) * term list) list) *
wenzelm@18771
    14
    Proof.context
wenzelm@18771
    15
  val cert_specification: (string * typ option * mixfix) list ->
wenzelm@18771
    16
    ((string * Attrib.src list) * term list) list -> Proof.context ->
wenzelm@18771
    17
    (((string * typ) * mixfix) list * ((string * Attrib.src list) * term list) list) *
wenzelm@18771
    18
    Proof.context
wenzelm@18771
    19
  val axiomatization: xstring option -> (string * string option * mixfix) list ->
wenzelm@18771
    20
    ((bstring * Attrib.src list) * string list) list -> theory ->
wenzelm@18771
    21
    (term list * (bstring * thm list) list) * (theory * Proof.context)
wenzelm@18771
    22
  val axiomatization_i: string option -> (string * typ option * mixfix) list ->
wenzelm@18771
    23
    ((bstring * Attrib.src list) * term list) list -> theory ->
wenzelm@18771
    24
    (term list * (bstring * thm list) list) * (theory * Proof.context)
wenzelm@18620
    25
end;
wenzelm@18620
    26
wenzelm@18620
    27
structure Specification: SPECIFICATION =
wenzelm@18620
    28
struct
wenzelm@18620
    29
wenzelm@18620
    30
(* prepare specification *)
wenzelm@18620
    31
wenzelm@18670
    32
fun prep_specification prep_vars prep_propp prep_att
wenzelm@18771
    33
    raw_vars raw_specs ctxt =
wenzelm@18620
    34
  let
wenzelm@18670
    35
    val thy = ProofContext.theory_of ctxt;
wenzelm@18620
    36
wenzelm@18670
    37
    val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars;
wenzelm@18670
    38
    val (xs, params_ctxt) = vars_ctxt |> ProofContext.add_fixes_i vars;
wenzelm@18670
    39
    val ((specs, vs), specs_ctxt) =
wenzelm@18620
    40
      prep_propp (params_ctxt, map (map (rpair ([], [])) o snd) raw_specs)
wenzelm@18620
    41
      |> swap |>> map (map fst)
wenzelm@18771
    42
      ||>> fold_map ProofContext.inferred_param xs;
wenzelm@18620
    43
wenzelm@18771
    44
    val params = vs ~~ map #3 vars;
wenzelm@18620
    45
    val names = map (fst o fst) raw_specs;
wenzelm@18670
    46
    val atts = map (map (prep_att thy) o snd o fst) raw_specs;
wenzelm@18620
    47
  in ((params, (names ~~ atts) ~~ specs), specs_ctxt) end;
wenzelm@18620
    48
wenzelm@18620
    49
fun read_specification x =
wenzelm@18771
    50
  prep_specification ProofContext.read_vars ProofContext.read_propp Attrib.intern_src x;
wenzelm@18620
    51
fun cert_specification x =
wenzelm@18670
    52
  prep_specification ProofContext.cert_vars ProofContext.cert_propp (K I) x;
wenzelm@18620
    53
wenzelm@18620
    54
wenzelm@18771
    55
(* axiomatization *)
wenzelm@18620
    56
wenzelm@18771
    57
fun gen_axiomatization prep init locale raw_vars raw_specs thy =
wenzelm@18620
    58
  let
wenzelm@18771
    59
    val ((vars, specs), ctxt) = init locale thy |> prep raw_vars raw_specs;
wenzelm@18771
    60
    val (consts, consts_ctxt) = ctxt |> LocalTheory.consts vars;
wenzelm@18771
    61
    val subst = Term.subst_atomic (map (Free o fst) vars ~~ consts);
wenzelm@18771
    62
    val (axioms, axioms_ctxt) =
wenzelm@18771
    63
      consts_ctxt
wenzelm@18771
    64
      |> LocalTheory.axioms (specs |> map (fn (a, props) => (a, map subst props)))
wenzelm@18771
    65
      ||> LocalTheory.map_theory (Theory.add_finals_i false (map Term.head_of consts));
wenzelm@18771
    66
    val _ = Pretty.writeln (LocalTheory.pretty_consts ctxt (map fst vars));
wenzelm@18771
    67
  in ((consts, axioms), `LocalTheory.exit axioms_ctxt) end;
wenzelm@18620
    68
wenzelm@18771
    69
val axiomatization = gen_axiomatization read_specification LocalTheory.init;
wenzelm@18771
    70
val axiomatization_i = gen_axiomatization cert_specification LocalTheory.init_i;
wenzelm@18620
    71
wenzelm@18620
    72
end;