author | haftmann |
Thu, 04 Dec 2008 14:43:33 +0100 | |
changeset 28965 | 1de908189869 |
parent 28370 | 37f56e6e702d |
child 29006 | abe0f11cfa4e |
permissions | -rw-r--r-- |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/constdefs.ML |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius, Hagia Maria Sion Abbey (Jerusalem) |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
3 |
|
18779 | 4 |
Old-style constant definitions, with type-inference and optional |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
5 |
structure context; specifications need to observe strictly sequential |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
6 |
dependencies; no support for overloading. |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
7 |
*) |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
8 |
|
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
9 |
signature CONSTDEFS = |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
10 |
sig |
28965 | 11 |
val add_constdefs: (Binding.T * string option) list * |
12 |
((Binding.T * string option * mixfix) option * |
|
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28083
diff
changeset
|
13 |
(Attrib.binding * string)) list -> theory -> theory |
28965 | 14 |
val add_constdefs_i: (Binding.T * typ option) list * |
15 |
((Binding.T * typ option * mixfix) option * |
|
16 |
((Binding.T * attribute list) * term)) list -> theory -> theory |
|
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
17 |
end; |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
18 |
|
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
19 |
structure Constdefs: CONSTDEFS = |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
20 |
struct |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
21 |
|
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
22 |
(** add_constdefs(_i) **) |
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
23 |
|
22710 | 24 |
fun gen_constdef prep_vars prep_prop prep_att |
18668 | 25 |
structs (raw_decl, ((raw_name, raw_atts), raw_prop)) thy = |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
26 |
let |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
25352
diff
changeset
|
27 |
fun err msg ts = error (cat_lines (msg :: map (Syntax.string_of_term_global thy) ts)); |
14664 | 28 |
|
18948 | 29 |
val thy_ctxt = ProofContext.init thy; |
30 |
val struct_ctxt = #2 (ProofContext.add_fixes_i structs thy_ctxt); |
|
31 |
val ((d, mx), var_ctxt) = |
|
18668 | 32 |
(case raw_decl of |
18948 | 33 |
NONE => ((NONE, NoSyn), struct_ctxt) |
18668 | 34 |
| SOME raw_var => |
18948 | 35 |
struct_ctxt |> prep_vars [raw_var] |-> (fn [(x, T, mx)] => |
25352 | 36 |
ProofContext.add_fixes_i [(x, T, mx)] #> snd #> pair (SOME x, mx))); |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
37 |
|
22710 | 38 |
val prop = prep_prop var_ctxt raw_prop; |
18948 | 39 |
val (c, T) = #1 (LocalDefs.cert_def thy_ctxt (Logic.strip_imp_concl prop)); |
28083
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
40 |
val _ = |
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
41 |
(case Option.map Name.name_of d of |
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
42 |
NONE => () |
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
43 |
| SOME c' => |
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
44 |
if c <> c' then |
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
45 |
err ("Head of definition " ^ quote c ^ " differs from declaration " ^ quote c') [] |
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
46 |
else ()); |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
47 |
|
28965 | 48 |
val def = Term.subst_atomic [(Free (c, T), Const (Sign.full_bname thy c, T))] prop; |
28083
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27691
diff
changeset
|
49 |
val name = Thm.def_name_optional c (Name.name_of raw_name); |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
50 |
val atts = map (prep_att thy) raw_atts; |
14664 | 51 |
|
52 |
val thy' = |
|
53 |
thy |
|
22796 | 54 |
|> Sign.add_consts_i [(c, T, mx)] |
27691
ce171cbd4b93
PureThy: dropped note_thmss_qualified, dropped _i suffix
haftmann
parents:
26939
diff
changeset
|
55 |
|> PureThy.add_defs false [((name, def), atts)] |
28370 | 56 |
|-> (fn [thm] => Code.add_default_eqn thm); |
17853 | 57 |
in ((c, T), thy') end; |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
58 |
|
22710 | 59 |
fun gen_constdefs prep_vars prep_prop prep_att (raw_structs, specs) thy = |
14664 | 60 |
let |
18638 | 61 |
val ctxt = ProofContext.init thy; |
18668 | 62 |
val (structs, _) = prep_vars (map (fn (x, T) => (x, T, Structure)) raw_structs) ctxt; |
22710 | 63 |
val (decls, thy') = fold_map (gen_constdef prep_vars prep_prop prep_att structs) specs thy; |
20885 | 64 |
in Pretty.writeln (ProofDisplay.pretty_consts ctxt (K true) decls); thy' end; |
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
65 |
|
25352 | 66 |
val add_constdefs = gen_constdefs ProofContext.read_vars Syntax.read_prop Attrib.attribute; |
67 |
val add_constdefs_i = gen_constdefs ProofContext.cert_vars ProofContext.cert_prop (K I); |
|
14657
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
68 |
|
c7cc01735801
'constdefs' with automatic type-inference and structure context;
wenzelm
parents:
diff
changeset
|
69 |
end; |