author | oheimb |
Thu, 18 Dec 1997 12:50:58 +0100 | |
changeset 4435 | 41a7e4f0e957 |
parent 4329 | 9d99bfdd7441 |
child 4458 | ad8be126603d |
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 = |
|
4329 | 10 |
{args: string list, |
11 |
parent: (typ list * string) option, |
|
12 |
fields: (string * typ) list, |
|
13 |
sign_ref: Sign.sg_ref}; |
|
4127 | 14 |
|
15 |
(*for datatypes*) |
|
4082 | 16 |
type datatype_info = |
17 |
{case_const: term, |
|
18 |
case_rewrites: thm list, |
|
19 |
constructors: term list, |
|
20 |
induct_tac: string -> int -> tactic, |
|
21 |
nchotomy: thm, |
|
22 |
exhaustion: thm, |
|
23 |
exhaust_tac: string -> int -> tactic, |
|
24 |
case_cong: thm}; |
|
25 |
||
4127 | 26 |
|
4082 | 27 |
signature THY_DATA = |
28 |
sig |
|
4127 | 29 |
val get_records: theory -> record_info Symtab.table; |
30 |
val put_records: record_info Symtab.table -> theory -> theory; |
|
4105 | 31 |
val get_datatypes_sg: Sign.sg -> datatype_info Symtab.table |
32 |
val get_datatypes: theory -> datatype_info Symtab.table |
|
33 |
val put_datatypes: datatype_info Symtab.table -> theory -> theory |
|
4127 | 34 |
val hol_data: (string * (object * (object -> object) * |
4259 | 35 |
(object * object -> object) * (Sign.sg -> object -> unit))) list |
4082 | 36 |
end; |
37 |
||
38 |
structure ThyData: THY_DATA = |
|
39 |
struct |
|
40 |
||
41 |
||
4105 | 42 |
(** datatypes **) |
43 |
||
44 |
(* data kind 'datatypes' *) |
|
4082 | 45 |
|
46 |
val datatypesK = "datatypes"; |
|
47 |
exception DatatypeInfo of datatype_info Symtab.table; |
|
48 |
||
4105 | 49 |
local |
50 |
val empty = DatatypeInfo Symtab.null; |
|
51 |
||
52 |
fun prep_ext (x as DatatypeInfo _) = x; |
|
53 |
||
54 |
fun merge (DatatypeInfo tab1, DatatypeInfo tab2) = |
|
55 |
DatatypeInfo (Symtab.merge (K true) (tab1, tab2)); |
|
56 |
||
4259 | 57 |
fun print sg (DatatypeInfo tab) = |
58 |
Pretty.writeln (Pretty.strs ("datatypes:" :: |
|
59 |
map (Sign.cond_extern sg Sign.typeK o fst) (Symtab.dest tab))); |
|
4105 | 60 |
in |
61 |
val datatypes_thy_data = (datatypesK, (empty, prep_ext, merge, print)); |
|
4127 | 62 |
end; |
63 |
||
64 |
||
65 |
(* get and put datatypes *) |
|
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
66 |
|
4127 | 67 |
fun get_datatypes_sg sg = |
68 |
(case Sign.get_data sg datatypesK of |
|
69 |
DatatypeInfo tab => tab |
|
70 |
| _ => sys_error "get_datatypes_sg"); |
|
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
71 |
|
4127 | 72 |
val get_datatypes = get_datatypes_sg o sign_of; |
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
73 |
|
4127 | 74 |
fun put_datatypes tab thy = |
75 |
Theory.put_data (datatypesK, DatatypeInfo tab) thy; |
|
76 |
||
4082 | 77 |
|
78 |
||
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
79 |
(** records **) |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
80 |
|
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
81 |
(* data kind 'records' *) |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
82 |
|
4127 | 83 |
val recordsK = "records"; |
84 |
exception Records of record_info Symtab.table; |
|
85 |
||
86 |
||
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
87 |
(* methods *) |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
88 |
|
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
89 |
local |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
90 |
val empty = Records Symtab.null; |
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
91 |
|
4127 | 92 |
fun prep_ext (x as Records _) = x; |
4120
57c1e7d70960
data kinds 'datatypes', data kinds 'records' added
narasche
parents:
4105
diff
changeset
|
93 |
|
4127 | 94 |
fun merge (Records tab1, Records tab2) = |
95 |
Records (Symtab.merge (K true) (tab1, tab2)); |
|
4105 | 96 |
|
4259 | 97 |
fun print sg (Records tab) = |
4127 | 98 |
let |
4329 | 99 |
fun pretty_args args = Pretty.lst ("(", ")") (map Pretty.str args); |
100 |
||
101 |
fun pretty_parent sign None = [] |
|
102 |
| pretty_parent sign (Some (ts, name)) = |
|
103 |
(Pretty.lst ("(", ")") (map (Sign.pretty_typ sign) ts)) :: [Pretty.str (name ^ " +")]; |
|
4127 | 104 |
|
4329 | 105 |
fun pretty_field sign (c, T) = Pretty.block |
106 |
[Pretty.str (c ^ " :: "), Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)]; |
|
4105 | 107 |
|
4329 | 108 |
fun pretty_record (name, {args, parent, fields, sign_ref}) = |
109 |
let val sign = Sign.deref sign_ref in |
|
110 |
Pretty.block |
|
111 |
(Pretty.fbreaks |
|
112 |
((Pretty.block ((pretty_args args) :: [Pretty.str (" " ^ name ^ " =")])) :: |
|
113 |
pretty_parent sign parent @ map (pretty_field sign) fields)) |
|
114 |
end |
|
4127 | 115 |
in |
116 |
seq (Pretty.writeln o pretty_record) (Symtab.dest tab) |
|
117 |
end; |
|
118 |
in |
|
119 |
val record_thy_data = (recordsK, (empty, prep_ext, merge, print)); |
|
120 |
end; |
|
121 |
||
4082 | 122 |
|
4127 | 123 |
(* get and put records *) |
4082 | 124 |
|
4127 | 125 |
fun get_records thy = |
126 |
(case Theory.get_data thy recordsK of |
|
127 |
Records tab => tab |
|
128 |
| _ => sys_error "get_records"); |
|
129 |
||
130 |
fun put_records tab thy = |
|
131 |
Theory.put_data (recordsK, Records tab) thy; |
|
132 |
||
4082 | 133 |
|
134 |
||
135 |
(** hol_data **) |
|
136 |
||
137 |
val hol_data = |
|
4259 | 138 |
[Simplifier.simpset_thy_data, |
139 |
ClasetThyData.thy_data, |
|
4127 | 140 |
datatypes_thy_data, |
141 |
record_thy_data]; |
|
142 |
||
4082 | 143 |
|
144 |
end; |