workaround: in internalize_sort, Thm.unconstrainT can rename type variables and therefore invalidate new_tvar
authorimmler
Tue, 12 Jun 2018 19:30:55 +0200
changeset 68429 38961724a017
parent 68428 46beee72fb66
child 68430 b0eb6a91924d
workaround: in internalize_sort, Thm.unconstrainT can rename type variables and therefore invalidate new_tvar
src/HOL/Types_To_Sets/unoverload_type.ML
--- a/src/HOL/Types_To_Sets/unoverload_type.ML	Tue Jun 12 16:21:52 2018 +0200
+++ b/src/HOL/Types_To_Sets/unoverload_type.ML	Tue Jun 12 19:30:55 2018 +0200
@@ -27,6 +27,18 @@
       List.concat
   in params end
 
+fun internalize_sort' ctvar thm =
+  let
+    val (_, thm') = Internalize_Sort.internalize_sort ctvar thm
+    val class_premise = case Thm.prems_of thm' of t::_=> t | [] =>
+      raise THM ("unoverload_type: no premise?", 0, [thm'])
+    val class_vars = Term.add_tvars class_premise []
+    val tvar = case class_vars of [x] => TVar x | _ =>
+      raise TERM ("unoverload_type: not one type class variable.", [class_premise])
+  in
+    (tvar, thm')
+  end
+
 fun unoverload_type context s thm =
   let
     val tvars = Term.add_tvars (Thm.prop_of thm) []
@@ -36,7 +48,7 @@
     raise THM ("unoverload_internalize_deps: type variable ("^s^") not in theorem", 0, [thm])
   | SOME (x as (_, sort)) =>
     let
-      val (tvar, thm') = Internalize_Sort.internalize_sort (Thm.global_ctyp_of thy (TVar x)) thm
+      val (tvar, thm') = internalize_sort' (Thm.global_ctyp_of thy (TVar x)) thm
       val consts = params_of_sort context sort |>
         map (apsnd (map_type_tfree (fn ("'a", _) =>  tvar | x => TFree x)))
     in