11 |
11 |
12 val class: bstring -> class list -> Element.context_i Locale.element list -> theory -> |
12 val class: bstring -> class list -> Element.context_i Locale.element list -> theory -> |
13 string * Proof.context |
13 string * Proof.context |
14 val class_cmd: bstring -> string list -> Element.context Locale.element list -> theory -> |
14 val class_cmd: bstring -> string list -> Element.context Locale.element list -> theory -> |
15 string * Proof.context |
15 string * Proof.context |
16 val instance_arity: ((bstring * sort list) * sort) list |
16 val instance_arity: arity list -> ((bstring * Attrib.src list) * term) list |
17 -> ((bstring * Attrib.src list) * term) list |
|
18 -> theory -> Proof.state |
17 -> theory -> Proof.state |
19 val instance_arity_cmd: ((bstring * string list) * string) list |
18 val instance_arity_cmd: (bstring * string list * string) list |
20 -> ((bstring * Attrib.src list) * string) list |
19 -> ((bstring * Attrib.src list) * string) list |
21 -> theory -> Proof.state |
20 -> theory -> Proof.state |
22 val prove_instance_arity: tactic -> ((string * sort list) * sort) list |
21 val prove_instance_arity: tactic -> arity list |
23 -> ((bstring * Attrib.src list) * term) list |
22 -> ((bstring * Attrib.src list) * term) list |
24 -> theory -> theory |
23 -> theory -> theory |
25 val instance_class: class * class -> theory -> Proof.state |
24 val instance_class: class * class -> theory -> Proof.state |
26 val instance_class_cmd: string * string -> theory -> Proof.state |
25 val instance_class_cmd: string * string -> theory -> Proof.state |
27 val instance_sort: class * sort -> theory -> Proof.state |
26 val instance_sort: class * sort -> theory -> Proof.state |
28 val instance_sort_cmd: string * string -> theory -> Proof.state |
27 val instance_sort_cmd: string * string -> theory -> Proof.state |
29 val prove_instance_sort: tactic -> class * sort -> theory -> theory |
28 val prove_instance_sort: tactic -> class * sort -> theory -> theory |
30 |
29 |
31 val assume_arities_of_sort: theory -> ((string * sort list) * sort) list -> typ * sort -> bool |
30 val assume_arities_of_sort: theory -> arity list -> typ * sort -> bool |
32 val assume_arities_thy: theory -> ((string * sort list) * sort) list -> (theory -> 'a) -> 'a |
|
33 (*'a must not keep any reference to theory*) |
|
34 |
31 |
35 (* experimental class target *) |
32 (* experimental class target *) |
36 val class_of_locale: theory -> string -> class option |
33 val class_of_locale: theory -> string -> class option |
37 val add_def_in_class: local_theory -> string |
34 val add_def_in_class: local_theory -> string |
38 -> (string * Syntax.mixfix) * ((string * Attrib.src list) * (term * thm)) -> theory -> theory |
35 -> (string * Syntax.mixfix) * ((string * Attrib.src list) * (term * thm)) -> theory -> theory |
111 |
108 |
112 fun assume_arities_of_sort thy arities ty_sort = |
109 fun assume_arities_of_sort thy arities ty_sort = |
113 let |
110 let |
114 val pp = Sign.pp thy; |
111 val pp = Sign.pp thy; |
115 val algebra = Sign.classes_of thy |
112 val algebra = Sign.classes_of thy |
116 |> fold (fn ((tyco, asorts), sort) => |
113 |> fold (fn (tyco, asorts, sort) => |
117 Sorts.add_arities pp (tyco, map (fn class => (class, asorts)) sort)) arities; |
114 Sorts.add_arities pp (tyco, map (fn class => (class, asorts)) sort)) arities; |
118 in Sorts.of_sort algebra ty_sort end; |
115 in Sorts.of_sort algebra ty_sort end; |
119 |
|
120 fun assume_arities_thy thy arities f = |
|
121 let |
|
122 val thy_read = (fold (fn ((tyco, asorts), sort) |
|
123 => Sign.primitive_arity (tyco, asorts, sort)) arities o Theory.copy) thy |
|
124 in f thy_read end; |
|
125 |
116 |
126 |
117 |
127 (* instances with implicit parameter handling *) |
118 (* instances with implicit parameter handling *) |
128 |
119 |
129 local |
120 local |
142 fun read_def_cmd thy = gen_read_def thy Attrib.intern_src read_axm; |
133 fun read_def_cmd thy = gen_read_def thy Attrib.intern_src read_axm; |
143 fun read_def thy = gen_read_def thy (K I) (K I); |
134 fun read_def thy = gen_read_def thy (K I) (K I); |
144 |
135 |
145 fun gen_instance_arity prep_arity read_def do_proof raw_arities raw_defs theory = |
136 fun gen_instance_arity prep_arity read_def do_proof raw_arities raw_defs theory = |
146 let |
137 let |
147 fun prep_arity' ((tyco, asorts), sort) = prep_arity theory (tyco, asorts, sort); |
138 val arities = map (prep_arity theory) raw_arities; |
148 val arities = map prep_arity' raw_arities; |
|
149 val arities_pair = map (fn (tyco, asorts, sort) => ((tyco, asorts), sort)) arities; |
|
150 val _ = if null arities then error "at least one arity must be given" else (); |
139 val _ = if null arities then error "at least one arity must be given" else (); |
151 val _ = case (duplicates (op =) o map #1) arities |
140 val _ = case (duplicates (op =) o map #1) arities |
152 of [] => () |
141 of [] => () |
153 | dupl_tycos => error ("type constructors occur more than once in arities: " |
142 | dupl_tycos => error ("type constructors occur more than once in arities: " |
154 ^ (commas o map quote) dupl_tycos); |
143 ^ (commas o map quote) dupl_tycos); |
185 of NONE => error ("superfluous definition for constant " ^ |
174 of NONE => error ("superfluous definition for constant " ^ |
186 quote c ^ "::" ^ Sign.string_of_typ thy_read ty) |
175 quote c ^ "::" ^ Sign.string_of_typ thy_read ty) |
187 | SOME norm => map_types norm t |
176 | SOME norm => map_types norm t |
188 in (((class, tyco), ((name, t'), atts)), AList.delete (op =) c cs) end; |
177 in (((class, tyco), ((name, t'), atts)), AList.delete (op =) c cs) end; |
189 in fold_map read defs cs end; |
178 in fold_map read defs cs end; |
190 val (defs, _) = assume_arities_thy theory arities_pair (read_defs raw_defs cs); |
179 val (defs, _) = read_defs raw_defs cs |
|
180 (fold Sign.primitive_arity arities (Theory.copy theory)); |
|
181 |
191 fun get_remove_contraint c thy = |
182 fun get_remove_contraint c thy = |
192 let |
183 let |
193 val ty = Sign.the_const_constraint thy c; |
184 val ty = Sign.the_const_constraint thy c; |
194 in |
185 in |
195 thy |
186 thy |
270 of NONE => error ("undeclared class " ^ quote class) |
261 of NONE => error ("undeclared class " ^ quote class) |
271 | SOME data => data; |
262 | SOME data => data; |
272 |
263 |
273 val ancestry = Graph.all_succs o fst o ClassData.get; |
264 val ancestry = Graph.all_succs o fst o ClassData.get; |
274 |
265 |
275 fun param_map thy = |
266 fun param_map thy = |
276 let |
267 let |
277 fun params thy class = |
268 fun params thy class = |
278 let |
269 let |
279 val const_typs = (#params o AxClass.get_definition thy) class; |
270 val const_typs = (#params o AxClass.get_definition thy) class; |
280 val const_names = (#consts o the_class_data thy) class; |
271 val const_names = (#consts o the_class_data thy) class; |