author | wenzelm |
Tue, 04 Nov 1997 16:49:35 +0100 | |
changeset 4127 | e0382d653d62 |
parent 4120 | 57c1e7d70960 |
child 4150 | 56025371fc02 |
permissions | -rw-r--r-- |
4082 | 1 |
(* Title: HOL/thy_data.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
4127 | 5 |
HOL theory data: simpset, claset, records, datatypes. |
4082 | 6 |
*) |
7 |
||
4127 | 8 |
(*for records*) |
9 |
type record_info = |
|
10 |
{parent: string option, |
|
11 |
selectors: (string * ctyp) list}; |
|
12 |
||
13 |
(*for datatypes*) |
|
4082 | 14 |
type datatype_info = |
15 |
{case_const: term, |
|
16 |
case_rewrites: thm list, |
|
17 |
constructors: term list, |
|
18 |
induct_tac: string -> int -> tactic, |
|
19 |
nchotomy: thm, |
|
20 |
exhaustion: thm, |
|
21 |
exhaust_tac: string -> int -> tactic, |
|
22 |
case_cong: thm}; |
|
23 |
||
4127 | 24 |
|
4082 | 25 |
signature THY_DATA = |
26 |
sig |
|
4127 | 27 |
val get_records: theory -> record_info Symtab.table; |
28 |
val put_records: record_info Symtab.table -> theory -> theory; |
|
4105 | 29 |
val get_datatypes_sg: Sign.sg -> datatype_info Symtab.table |
30 |
val get_datatypes: theory -> datatype_info Symtab.table |
|
31 |
val put_datatypes: datatype_info Symtab.table -> theory -> theory |
|
4127 | 32 |
val hol_data: (string * (object * (object -> object) * |
33 |
(object * object -> object) * (object -> unit))) list |
|
4082 | 34 |
end; |
35 |
||
36 |
structure ThyData: THY_DATA = |
|
37 |
struct |
|
38 |
||
39 |
||
4105 | 40 |
(** datatypes **) |
41 |
||
42 |
(* data kind 'datatypes' *) |
|
4082 | 43 |
|
44 |
val datatypesK = "datatypes"; |
|
45 |
exception DatatypeInfo of datatype_info Symtab.table; |
|
46 |
||
4105 | 47 |
local |
48 |
val empty = DatatypeInfo Symtab.null; |
|
49 |
||
50 |
fun prep_ext (x as DatatypeInfo _) = x; |
|
51 |
||
52 |
fun merge (DatatypeInfo tab1, DatatypeInfo tab2) = |
|
53 |
DatatypeInfo (Symtab.merge (K true) (tab1, tab2)); |
|
54 |
||
55 |
fun print (DatatypeInfo tab) = |
|
56 |
Pretty.writeln (Pretty.strs ("datatypes:" :: map fst (Symtab.dest tab))); |
|
57 |
in |
|
58 |
val datatypes_thy_data = (datatypesK, (empty, prep_ext, merge, print)); |
|
4127 | 59 |
end; |
60 |
||
61 |
||
62 |
(* get and put datatypes *) |
|
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
63 |
|
4127 | 64 |
fun get_datatypes_sg sg = |
65 |
(case Sign.get_data sg datatypesK of |
|
66 |
DatatypeInfo tab => tab |
|
67 |
| _ => sys_error "get_datatypes_sg"); |
|
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
68 |
|
4127 | 69 |
val get_datatypes = get_datatypes_sg o sign_of; |
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
70 |
|
4127 | 71 |
fun put_datatypes tab thy = |
72 |
Theory.put_data (datatypesK, DatatypeInfo tab) thy; |
|
73 |
||
4082 | 74 |
|
75 |
||
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
76 |
(** records **) |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
77 |
|
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
78 |
(* data kind 'records' *) |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
79 |
|
4127 | 80 |
val recordsK = "records"; |
81 |
exception Records of record_info Symtab.table; |
|
82 |
||
83 |
||
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
84 |
(* methods *) |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
85 |
|
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
86 |
local |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
87 |
val empty = Records Symtab.null; |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
88 |
|
4127 | 89 |
fun prep_ext (x as Records _) = x; |
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
90 |
|
4127 | 91 |
fun merge (Records tab1, Records tab2) = |
92 |
Records (Symtab.merge (K true) (tab1, tab2)); |
|
4105 | 93 |
|
4127 | 94 |
fun print (Records tab) = |
95 |
let |
|
96 |
fun pretty_parent None = [] |
|
97 |
| pretty_parent (Some name) = [Pretty.str (name ^ " +")]; |
|
98 |
||
99 |
fun pretty_sel (c, T) = Pretty.block |
|
100 |
[Pretty.str (c ^ " :: "), Pretty.brk 1, Pretty.quote (Display.pretty_ctyp T)]; |
|
4105 | 101 |
|
4127 | 102 |
fun pretty_record (name, {parent, selectors}) = |
103 |
Pretty.big_list (name ^ " =") (pretty_parent parent @ map pretty_sel selectors); |
|
104 |
in |
|
105 |
seq (Pretty.writeln o pretty_record) (Symtab.dest tab) |
|
106 |
end; |
|
107 |
in |
|
108 |
val record_thy_data = (recordsK, (empty, prep_ext, merge, print)); |
|
109 |
end; |
|
110 |
||
4082 | 111 |
|
4127 | 112 |
(* get and put records *) |
4082 | 113 |
|
4127 | 114 |
fun get_records thy = |
115 |
(case Theory.get_data thy recordsK of |
|
116 |
Records tab => tab |
|
117 |
| _ => sys_error "get_records"); |
|
118 |
||
119 |
fun put_records tab thy = |
|
120 |
Theory.put_data (recordsK, Records tab) thy; |
|
121 |
||
4082 | 122 |
|
123 |
||
124 |
(** hol_data **) |
|
125 |
||
126 |
val hol_data = |
|
4127 | 127 |
[Simplifier.simpset_thy_data, (*see Provers/simplifier.ML*) |
128 |
ClasetThyData.thy_data, (*see Provers/classical.ML*) |
|
129 |
datatypes_thy_data, |
|
130 |
record_thy_data]; |
|
131 |
||
4082 | 132 |
|
133 |
end; |