258 end; |
258 end; |
259 |
259 |
260 fun typ_subst env = apsnd (Term.typ_subst_TVars env); |
260 fun typ_subst env = apsnd (Term.typ_subst_TVars env); |
261 fun subst env = apsnd (Term.subst_TVars env); |
261 fun subst env = apsnd (Term.subst_TVars env); |
262 |
262 |
263 fun instantiate sign envT env = |
263 fun instantiate sign envT env thm = |
264 let |
264 let |
265 fun prepT (a, T) = (a, Thm.ctyp_of sign T); |
265 val (_, sorts) = Drule.types_sorts thm; |
|
266 fun prepT (a, T) = (Thm.ctyp_of sign (TVar (a, the_sort sorts a)), Thm.ctyp_of sign T); |
266 fun prep (xi, t) = pairself (Thm.cterm_of sign) (Var (xi, Term.fastype_of t), t); |
267 fun prep (xi, t) = pairself (Thm.cterm_of sign) (Var (xi, Term.fastype_of t), t); |
267 in |
268 in |
268 Drule.instantiate (map prepT (distinct envT), |
269 Drule.instantiate (map prepT (distinct envT), |
269 map prep (gen_distinct (fn ((xi, t), (yj, u)) => xi = yj andalso t aconv u) env)) |
270 map prep (gen_distinct (fn ((xi, t), (yj, u)) => xi = yj andalso t aconv u) env)) thm |
270 end; |
271 end; |
271 |
272 |
272 in |
273 in |
273 |
274 |
274 fun read_instantiate init mixed_insts (context, thm) = |
275 fun read_instantiate init mixed_insts (context, thm) = |
307 |
308 |
308 |
309 |
309 (* internal term instantiations *) |
310 (* internal term instantiations *) |
310 |
311 |
311 val types' = #1 (Drule.types_sorts thm'); |
312 val types' = #1 (Drule.types_sorts thm'); |
312 val unifier = Vartab.dest (#1 |
313 val unifier = map (apsnd snd) (Vartab.dest (#1 |
313 (Library.foldl (unify_types sign types') ((Vartab.empty, 0), internal_insts))); |
314 (Library.foldl (unify_types sign types') ((Vartab.empty, 0), internal_insts)))); |
314 |
315 |
315 val type_insts'' = map (typ_subst unifier) type_insts'; |
316 val type_insts'' = map (typ_subst unifier) type_insts'; |
316 val internal_insts'' = map (subst unifier) internal_insts; |
317 val internal_insts'' = map (subst unifier) internal_insts; |
317 val thm'' = instantiate sign unifier internal_insts'' thm'; |
318 val thm'' = instantiate sign unifier internal_insts'' thm'; |
318 |
319 |