nicer error message, indicating which type is empty (relying on metatheoretical completeness proof here)
authorblanchet
Wed, 12 Sep 2012 23:06:39 +0200
changeset 49341 d406979024d1
parent 49339 d1fcb4de8349
child 49342 8ea4bad49ed5
nicer error message, indicating which type is empty (relying on metatheoretical completeness proof here)
src/HOL/Codatatype/Tools/bnf_lfp.ML
--- a/src/HOL/Codatatype/Tools/bnf_lfp.ML	Wed Sep 12 22:00:29 2012 +0200
+++ b/src/HOL/Codatatype/Tools/bnf_lfp.ML	Wed Sep 12 23:06:39 2012 +0200
@@ -152,19 +152,21 @@
     (* nonemptiness check *)
     fun new_wit X wit = subset (op =) (#I wit, (0 upto m - 1) @ map snd X);
 
+    val all = m upto m + n - 1;
+
     fun enrich X = map_filter (fn i =>
       (case find_first (fn (_, i') => i = i') X of
         NONE =>
           (case find_index (new_wit X) (nth witss (i - m)) of
             ~1 => NONE
           | j => SOME (j, i))
-      | SOME ji => SOME ji)) (m upto m + n - 1);
+      | SOME ji => SOME ji)) all;
     val reachable = fixpoint (op =) enrich [];
-    val _ = if map snd reachable = (m upto m + n - 1) then ()
-      else error "The datatype could not be generated because nonemptiness could not be proved";
+    val _ = (case subtract (op =) (map snd reachable) all of
+        [] => ()
+      | i :: _ => error ("Invalid empty datatype " ^ quote (Binding.name_of (nth bs (i - m)))));
 
-    val wit_thms =
-      flat (map2 (fn bnf => fn (j, _) => nth (wit_thmss_of_bnf bnf) j) bnfs reachable);
+    val wit_thms = flat (map2 (fn bnf => fn (j, _) => nth (wit_thmss_of_bnf bnf) j) bnfs reachable);
 
     val timer = time (timer "Checked nonemptiness");