142 val add_tvars = Thm.fold_atomic_ctyps (fn a => is_TVar (Thm.typ_of a) ? insert eq_ctyp a); |
142 val add_tvars = Thm.fold_atomic_ctyps (fn a => is_TVar (Thm.typ_of a) ? insert eq_ctyp a); |
143 val add_frees = Thm.fold_atomic_cterms (fn a => is_Free (Thm.term_of a) ? insert (op aconvc) a); |
143 val add_frees = Thm.fold_atomic_cterms (fn a => is_Free (Thm.term_of a) ? insert (op aconvc) a); |
144 val add_vars = Thm.fold_atomic_cterms (fn a => is_Var (Thm.term_of a) ? insert (op aconvc) a); |
144 val add_vars = Thm.fold_atomic_cterms (fn a => is_Var (Thm.term_of a) ? insert (op aconvc) a); |
145 |
145 |
146 |
146 |
147 (* ctyp destructors *) |
147 (* ctyp operations *) |
148 |
148 |
149 fun dest_ctyp_fun cT = |
149 fun dest_ctyp_fun cT = |
150 let |
150 (case Thm.typ_of cT of |
151 val T = Thm.typ_of cT; |
151 Type ("fun", _) => let val [A, B] = Thm.dest_ctyp cT in (A, B) end |
152 fun dest_ctyp_nth i = Thm.dest_ctyp_nth i cT; |
152 | T => raise TYPE ("dest_ctyp_fun", [T], [])); |
153 in |
|
154 (case T of |
|
155 Type ("fun", _) => (dest_ctyp_nth 0, dest_ctyp_nth 1) |
|
156 | _ => raise TYPE ("dest_ctyp_fun", [T], [])) |
|
157 end; |
|
158 |
153 |
159 (* ctyp version of strip_type: maps [T1,...,Tn]--->T to ([T1,T2,...,Tn], T) *) |
154 (* ctyp version of strip_type: maps [T1,...,Tn]--->T to ([T1,T2,...,Tn], T) *) |
160 fun strip_type cT = |
155 fun strip_type cT = |
161 (case Thm.typ_of cT of |
156 (case Thm.typ_of cT of |
162 Type ("fun", _) => |
157 Type ("fun", _) => |
165 val (cTs, cT') = strip_type cT2 |
160 val (cTs, cT') = strip_type cT2 |
166 in (cT1 :: cTs, cT') end |
161 in (cT1 :: cTs, cT') end |
167 | _ => ([], cT)); |
162 | _ => ([], cT)); |
168 |
163 |
169 |
164 |
170 (* cterm constructors and destructors *) |
165 (* cterm operations *) |
171 |
166 |
172 fun all_name ctxt (x, t) A = |
167 fun all_name ctxt (x, t) A = |
173 let |
168 let |
174 val T = Thm.typ_of_cterm t; |
169 val T = Thm.typ_of_cterm t; |
175 val all_const = Thm.cterm_of ctxt (Const ("Pure.all", (T --> propT) --> propT)); |
170 val all_const = Thm.cterm_of ctxt (Const ("Pure.all", (T --> propT) --> propT)); |