src/Pure/Isar/specification.ML
author wenzelm
Sat Jan 21 23:02:14 2006 +0100 (2006-01-21)
changeset 18728 6790126ab5f6
parent 18670 c3f445b92aff
child 18771 63efe00371af
permissions -rw-r--r--
simplified type attribute;
     1 (*  Title:      Pure/Isar/specification.ML
     2     ID:         $Id$
     3     Author:     Makarius
     4 
     5 Theory specifications --- with type-inference, but no internal
     6 polymorphism.
     7 *)
     8 
     9 signature SPECIFICATION =
    10 sig
    11   val pretty_consts: Proof.context -> (string * typ) list -> Pretty.T
    12   val read_specification:
    13     (string * string option * mixfix) list *
    14       ((string * Attrib.src list) * string list) list -> Proof.context ->
    15     ((string * typ * mixfix) list *
    16       ((string * attribute list) * term list) list) * Proof.context
    17   val cert_specification:
    18     (string * typ option * mixfix) list *
    19       ((string * attribute list) * term list) list -> Proof.context ->
    20     ((string * typ * mixfix) list *
    21       ((string * attribute list) * term list) list) * Proof.context
    22   val axiomatize:
    23     (string * string option * mixfix) list *
    24       ((bstring * Attrib.src list) * string list) list -> theory -> thm list list * theory
    25   val axiomatize_i:
    26     (string * typ option * mixfix) list *
    27       ((bstring * attribute list) * term list) list -> theory ->
    28     thm list list * theory
    29 end;
    30 
    31 structure Specification: SPECIFICATION =
    32 struct
    33 
    34 (* pretty_consts *)
    35 
    36 fun pretty_const ctxt (c, T) =
    37   Pretty.block [Pretty.str c, Pretty.str " ::", Pretty.brk 1,
    38     Pretty.quote (ProofContext.pretty_typ ctxt T)];
    39 
    40 fun pretty_consts ctxt decls =
    41   Pretty.big_list "constants" (map (pretty_const ctxt) decls);
    42 
    43 
    44 (* prepare specification *)
    45 
    46 fun prep_specification prep_vars prep_propp prep_att
    47     (raw_vars, raw_specs) ctxt =
    48   let
    49     val thy = ProofContext.theory_of ctxt;
    50 
    51     val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars;
    52     val (xs, params_ctxt) = vars_ctxt |> ProofContext.add_fixes_i vars;
    53     val ((specs, vs), specs_ctxt) =
    54       prep_propp (params_ctxt, map (map (rpair ([], [])) o snd) raw_specs)
    55       |> swap |>> map (map fst)
    56       ||>> fold_map ProofContext.inferred_type xs;
    57 
    58     val params = map2 (fn (x, T) => fn (_, _, mx) => (x, T, mx)) vs vars;
    59     val names = map (fst o fst) raw_specs;
    60     val atts = map (map (prep_att thy) o snd o fst) raw_specs;
    61   in ((params, (names ~~ atts) ~~ specs), specs_ctxt) end;
    62 
    63 fun read_specification x =
    64   prep_specification ProofContext.read_vars ProofContext.read_propp Attrib.attribute x;
    65 fun cert_specification x =
    66   prep_specification ProofContext.cert_vars ProofContext.cert_propp (K I) x;
    67 
    68 
    69 (* axiomatize *)
    70 
    71 fun gen_axiomatize prep args thy =
    72   let
    73     val ((consts, specs), ctxt) = prep args (ProofContext.init thy);
    74     val subst = consts |> map (fn (x, T, _) => (Free (x, T), Const (Sign.full_name thy x, T)));
    75     val axioms = specs |> map (fn ((name, att), ts) =>
    76       ((name, map (Term.subst_atomic subst) ts), att));
    77     val (thms, thy') =
    78       thy
    79       |> Theory.add_consts_i consts
    80       |> PureThy.add_axiomss_i axioms
    81       ||> Theory.add_finals_i false (map snd subst);
    82   in Pretty.writeln (pretty_consts ctxt (map (dest_Free o fst) subst)); (thms, thy') end;
    83 
    84 val axiomatize = gen_axiomatize read_specification;
    85 val axiomatize_i = gen_axiomatize cert_specification;
    86 
    87 end;