21 sig |
21 sig |
22 include BASIC_THM |
22 include BASIC_THM |
23 (*certified types*) |
23 (*certified types*) |
24 val theory_of_ctyp: ctyp -> theory |
24 val theory_of_ctyp: ctyp -> theory |
25 val typ_of: ctyp -> typ |
25 val typ_of: ctyp -> typ |
26 val ctyp_of: theory -> typ -> ctyp |
26 val global_ctyp_of: theory -> typ -> ctyp |
|
27 val ctyp_of: Proof.context -> typ -> ctyp |
27 val dest_ctyp: ctyp -> ctyp list |
28 val dest_ctyp: ctyp -> ctyp list |
28 (*certified terms*) |
29 (*certified terms*) |
29 val theory_of_cterm: cterm -> theory |
30 val theory_of_cterm: cterm -> theory |
30 val term_of: cterm -> term |
31 val term_of: cterm -> term |
31 val typ_of_cterm: cterm -> typ |
32 val typ_of_cterm: cterm -> typ |
32 val ctyp_of_cterm: cterm -> ctyp |
33 val ctyp_of_cterm: cterm -> ctyp |
33 val maxidx_of_cterm: cterm -> int |
34 val maxidx_of_cterm: cterm -> int |
34 val cterm_of: theory -> term -> cterm |
35 val global_cterm_of: theory -> term -> cterm |
|
36 val cterm_of: Proof.context -> term -> cterm |
35 val dest_comb: cterm -> cterm * cterm |
37 val dest_comb: cterm -> cterm * cterm |
36 val dest_fun: cterm -> cterm |
38 val dest_fun: cterm -> cterm |
37 val dest_arg: cterm -> cterm |
39 val dest_arg: cterm -> cterm |
38 val dest_fun2: cterm -> cterm |
40 val dest_fun2: cterm -> cterm |
39 val dest_arg1: cterm -> cterm |
41 val dest_arg1: cterm -> cterm |
150 with |
152 with |
151 |
153 |
152 fun theory_of_ctyp (Ctyp {thy, ...}) = thy; |
154 fun theory_of_ctyp (Ctyp {thy, ...}) = thy; |
153 fun typ_of (Ctyp {T, ...}) = T; |
155 fun typ_of (Ctyp {T, ...}) = T; |
154 |
156 |
155 fun ctyp_of thy raw_T = |
157 fun global_ctyp_of thy raw_T = |
156 let |
158 let |
157 val T = Sign.certify_typ thy raw_T; |
159 val T = Sign.certify_typ thy raw_T; |
158 val maxidx = Term.maxidx_of_typ T; |
160 val maxidx = Term.maxidx_of_typ T; |
159 val sorts = Sorts.insert_typ T []; |
161 val sorts = Sorts.insert_typ T []; |
160 in Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts} end; |
162 in Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts} end; |
161 |
163 |
|
164 val ctyp_of = global_ctyp_of o Proof_Context.theory_of; |
|
165 |
162 fun dest_ctyp (Ctyp {thy, T = Type (_, Ts), maxidx, sorts}) = |
166 fun dest_ctyp (Ctyp {thy, T = Type (_, Ts), maxidx, sorts}) = |
163 map (fn T => Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts}) Ts |
167 map (fn T => Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts}) Ts |
164 | dest_ctyp cT = raise TYPE ("dest_ctyp", [typ_of cT], []); |
168 | dest_ctyp cT = raise TYPE ("dest_ctyp", [typ_of cT], []); |
165 |
169 |
166 |
170 |
181 fun ctyp_of_cterm (Cterm {thy, T, maxidx, sorts, ...}) = |
185 fun ctyp_of_cterm (Cterm {thy, T, maxidx, sorts, ...}) = |
182 Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts}; |
186 Ctyp {thy = thy, T = T, maxidx = maxidx, sorts = sorts}; |
183 |
187 |
184 fun maxidx_of_cterm (Cterm {maxidx, ...}) = maxidx; |
188 fun maxidx_of_cterm (Cterm {maxidx, ...}) = maxidx; |
185 |
189 |
186 fun cterm_of thy tm = |
190 fun global_cterm_of thy tm = |
187 let |
191 let |
188 val (t, T, maxidx) = Sign.certify_term thy tm; |
192 val (t, T, maxidx) = Sign.certify_term thy tm; |
189 val sorts = Sorts.insert_term t []; |
193 val sorts = Sorts.insert_term t []; |
190 in Cterm {thy = thy, t = t, T = T, maxidx = maxidx, sorts = sorts} end; |
194 in Cterm {thy = thy, t = t, T = T, maxidx = maxidx, sorts = sorts} end; |
|
195 |
|
196 val cterm_of = global_cterm_of o Proof_Context.theory_of; |
191 |
197 |
192 fun merge_thys0 (Cterm {thy = thy1, ...}) (Cterm {thy = thy2, ...}) = |
198 fun merge_thys0 (Cterm {thy = thy1, ...}) (Cterm {thy = thy2, ...}) = |
193 Theory.merge (thy1, thy2); |
199 Theory.merge (thy1, thy2); |
194 |
200 |
195 |
201 |
1158 *) |
1164 *) |
1159 fun of_class (cT, raw_c) = |
1165 fun of_class (cT, raw_c) = |
1160 let |
1166 let |
1161 val Ctyp {thy, T, ...} = cT; |
1167 val Ctyp {thy, T, ...} = cT; |
1162 val c = Sign.certify_class thy raw_c; |
1168 val c = Sign.certify_class thy raw_c; |
1163 val Cterm {t = prop, maxidx, sorts, ...} = cterm_of thy (Logic.mk_of_class (T, c)); |
1169 val Cterm {t = prop, maxidx, sorts, ...} = global_cterm_of thy (Logic.mk_of_class (T, c)); |
1164 in |
1170 in |
1165 if Sign.of_sort thy (T, [c]) then |
1171 if Sign.of_sort thy (T, [c]) then |
1166 Thm (deriv_rule0 (Proofterm.OfClass (T, c)), |
1172 Thm (deriv_rule0 (Proofterm.OfClass (T, c)), |
1167 {thy = thy, |
1173 {thy = thy, |
1168 tags = [], |
1174 tags = [], |