merged
authorwenzelm
Wed, 12 Aug 2015 03:07:01 +0200
changeset 60915 2986137093c6
parent 60909 3db3f4154e18 (diff)
parent 60914 f39d004f2ff4 (current diff)
child 60916 a6e2a667b0a8
merged
--- a/src/HOL/Eisbach/eisbach_rule_insts.ML	Wed Aug 12 02:40:39 2015 +0200
+++ b/src/HOL/Eisbach/eisbach_rule_insts.ML	Wed Aug 12 03:07:01 2015 +0200
@@ -14,10 +14,20 @@
 
 fun restore_tags thm = Thm.map_tags (K (Thm.get_tags thm));
 
+val mk_term_type_internal = Logic.protect o Logic.mk_term o Logic.mk_type;
+
+fun term_type_cases f g t = 
+  (case (try (Logic.dest_type o Logic.dest_term o Logic.unprotect) t) of
+    SOME T => f T
+  | NONE => 
+    (case (try Logic.dest_term t) of
+      SOME t => g t
+    | NONE => raise Fail "Lost encoded instantiation"))
+
 fun add_thm_insts ctxt thm =
   let
     val tyvars = Thm.fold_terms Term.add_tvars thm [];
-    val tyvars' = tyvars |> map (Logic.mk_term o Logic.mk_type o TVar);
+    val tyvars' = tyvars |> map (mk_term_type_internal o TVar);
 
     val tvars = Thm.fold_terms Term.add_vars thm [];
     val tvars' = tvars  |> map (Logic.mk_term o Var);
@@ -36,11 +46,8 @@
       |> Drule.dest_term
       |> Thm.term_of
       |> Logic.dest_conjunction_list
-      |> map Logic.dest_term
       |> (fn f => fold (fn t => fn (tys, ts) =>
-          (case try Logic.dest_type t of
-            SOME T => (T :: tys, ts)
-          | NONE => (tys, t :: ts))) f ([], []))
+          term_type_cases (fn T => (T :: tys, ts)) (fn t => (tys, t :: ts)) t) f ([], []))
       ||> rev
       |>> rev;
   in