removed old 'add_datatype' ML functions
authorblanchet
Wed Jan 03 11:06:29 2018 +0100 (18 months ago)
changeset 67333ac0b81ca3ed5
parent 67332 cb96edae56ef
child 67334 51a7c90fbf19
removed old 'add_datatype' ML functions
src/HOL/Tools/Old_Datatype/old_datatype.ML
     1.1 --- a/src/HOL/Tools/Old_Datatype/old_datatype.ML	Wed Jan 03 11:06:13 2018 +0100
     1.2 +++ b/src/HOL/Tools/Old_Datatype/old_datatype.ML	Wed Jan 03 11:06:29 2018 +0100
     1.3 @@ -1,10 +1,7 @@
     1.4  (*  Title:      HOL/Tools/Old_Datatype/old_datatype.ML
     1.5      Author:     Stefan Berghofer, TU Muenchen
     1.6  
     1.7 -Datatype package: definitional introduction of datatypes
     1.8 -with proof of characteristic theorems: injectivity / distinctness
     1.9 -of constructors and induction.  Main interface to datatypes
    1.10 -after full bootstrap of datatype package.
    1.11 +Pieces left from the old datatype package.
    1.12  *)
    1.13  
    1.14  signature OLD_DATATYPE =
    1.15 @@ -16,669 +13,16 @@
    1.16      (binding * (string * string option) list * mixfix) * (binding * string list * mixfix) list
    1.17    val read_specs: spec_cmd list -> theory -> spec list * Proof.context
    1.18    val check_specs: spec list -> theory -> spec list * Proof.context
    1.19 -  val add_datatype: config -> spec list -> theory -> string list * theory
    1.20 -  val add_datatype_cmd: config -> spec_cmd list -> theory -> string list * theory
    1.21  end;
    1.22  
    1.23  structure Old_Datatype : OLD_DATATYPE =
    1.24  struct
    1.25  
    1.26 -(** auxiliary **)
    1.27 -
    1.28  val distinct_lemma = @{lemma "f x \<noteq> f y ==> x \<noteq> y" by iprover};
    1.29 -val (_ $ (_ $ (_ $ (distinct_f $ _) $ _))) = hd (Thm.prems_of distinct_lemma);
    1.30 -
    1.31 -fun exh_thm_of (dt_info : Old_Datatype_Aux.info Symtab.table) tname =
    1.32 -  #exhaust (the (Symtab.lookup dt_info tname));
    1.33 -
    1.34 -val In0_inject = @{thm In0_inject};
    1.35 -val In1_inject = @{thm In1_inject};
    1.36 -val Scons_inject = @{thm Scons_inject};
    1.37 -val Leaf_inject = @{thm Leaf_inject};
    1.38 -val In0_eq = @{thm In0_eq};
    1.39 -val In1_eq = @{thm In1_eq};
    1.40 -val In0_not_In1 = @{thm In0_not_In1};
    1.41 -val In1_not_In0 = @{thm In1_not_In0};
    1.42 -val Lim_inject = @{thm Lim_inject};
    1.43 -val Inl_inject = @{thm Inl_inject};
    1.44 -val Inr_inject = @{thm Inr_inject};
    1.45 -val Suml_inject = @{thm Suml_inject};
    1.46 -val Sumr_inject = @{thm Sumr_inject};
    1.47 -
    1.48 -val datatype_injI =
    1.49 -  @{lemma "(\<And>x. \<forall>y. f x = f y \<longrightarrow> x = y) \<Longrightarrow> inj f" by (simp add: inj_on_def)};
    1.50 -
    1.51 -
    1.52 -(** proof of characteristic theorems **)
    1.53 -
    1.54 -fun representation_proofs (config : Old_Datatype_Aux.config)
    1.55 -    (dt_info : Old_Datatype_Aux.info Symtab.table) descr types_syntax constr_syntax case_names_induct
    1.56 -    thy =
    1.57 -  let
    1.58 -    val descr' = flat descr;
    1.59 -    val new_type_names = map (Binding.name_of o fst) types_syntax;
    1.60 -    val big_name = space_implode "_" new_type_names;
    1.61 -    val thy1 = Sign.add_path big_name thy;
    1.62 -    val big_rec_name = "rep_set_" ^ big_name;
    1.63 -    val rep_set_names' =
    1.64 -      if length descr' = 1 then [big_rec_name]
    1.65 -      else map (prefix (big_rec_name ^ "_") o string_of_int) (1 upto length descr');
    1.66 -    val rep_set_names = map (Sign.full_bname thy1) rep_set_names';
    1.67 -
    1.68 -    val tyvars = map (fn (_, (_, Ts, _)) => map Old_Datatype_Aux.dest_DtTFree Ts) (hd descr);
    1.69 -    val leafTs' = Old_Datatype_Aux.get_nonrec_types descr';
    1.70 -    val branchTs = Old_Datatype_Aux.get_branching_types descr';
    1.71 -    val branchT =
    1.72 -      if null branchTs then HOLogic.unitT
    1.73 -      else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) branchTs;
    1.74 -    val arities = remove (op =) 0 (Old_Datatype_Aux.get_arities descr');
    1.75 -    val unneeded_vars =
    1.76 -      subtract (op =) (fold Term.add_tfreesT (leafTs' @ branchTs) []) (hd tyvars);
    1.77 -    val leafTs = leafTs' @ map TFree unneeded_vars;
    1.78 -    val recTs = Old_Datatype_Aux.get_rec_types descr';
    1.79 -    val (newTs, oldTs) = chop (length (hd descr)) recTs;
    1.80 -    val sumT =
    1.81 -      if null leafTs then HOLogic.unitT
    1.82 -      else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) leafTs;
    1.83 -    val Univ_elT = HOLogic.mk_setT (Type (@{type_name Old_Datatype.node}, [sumT, branchT]));
    1.84 -    val UnivT = HOLogic.mk_setT Univ_elT;
    1.85 -    val UnivT' = Univ_elT --> HOLogic.boolT;
    1.86 -    val Collect = Const (@{const_name Collect}, UnivT' --> UnivT);
    1.87 -
    1.88 -    val In0 = Const (@{const_name Old_Datatype.In0}, Univ_elT --> Univ_elT);
    1.89 -    val In1 = Const (@{const_name Old_Datatype.In1}, Univ_elT --> Univ_elT);
    1.90 -    val Leaf = Const (@{const_name Old_Datatype.Leaf}, sumT --> Univ_elT);
    1.91 -    val Lim = Const (@{const_name Old_Datatype.Lim}, (branchT --> Univ_elT) --> Univ_elT);
    1.92 -
    1.93 -    (* make injections needed for embedding types in leaves *)
    1.94 -
    1.95 -    fun mk_inj T' x =
    1.96 -      let
    1.97 -        fun mk_inj' T n i =
    1.98 -          if n = 1 then x
    1.99 -          else
   1.100 -            let
   1.101 -              val n2 = n div 2;
   1.102 -              val Type (_, [T1, T2]) = T;
   1.103 -            in
   1.104 -              if i <= n2
   1.105 -              then Const (@{const_name Inl}, T1 --> T) $ mk_inj' T1 n2 i
   1.106 -              else Const (@{const_name Inr}, T2 --> T) $ mk_inj' T2 (n - n2) (i - n2)
   1.107 -            end;
   1.108 -      in mk_inj' sumT (length leafTs) (1 + find_index (fn T'' => T'' = T') leafTs) end;
   1.109 -
   1.110 -    (* make injections for constructors *)
   1.111 -
   1.112 -    fun mk_univ_inj ts = Balanced_Tree.access
   1.113 -      {left = fn t => In0 $ t,
   1.114 -        right = fn t => In1 $ t,
   1.115 -        init =
   1.116 -          if ts = [] then Const (@{const_name undefined}, Univ_elT)
   1.117 -          else foldr1 (HOLogic.mk_binop @{const_name Old_Datatype.Scons}) ts};
   1.118 -
   1.119 -    (* function spaces *)
   1.120 -
   1.121 -    fun mk_fun_inj T' x =
   1.122 -      let
   1.123 -        fun mk_inj T n i =
   1.124 -          if n = 1 then x
   1.125 -          else
   1.126 -            let
   1.127 -              val n2 = n div 2;
   1.128 -              val Type (_, [T1, T2]) = T;
   1.129 -              fun mkT U = (U --> Univ_elT) --> T --> Univ_elT;
   1.130 -            in
   1.131 -              if i <= n2 then Const (@{const_name Sum_Type.Suml}, mkT T1) $ mk_inj T1 n2 i
   1.132 -              else Const (@{const_name Sum_Type.Sumr}, mkT T2) $ mk_inj T2 (n - n2) (i - n2)
   1.133 -            end;
   1.134 -      in mk_inj branchT (length branchTs) (1 + find_index (fn T'' => T'' = T') branchTs) end;
   1.135 -
   1.136 -    fun mk_lim t Ts = fold_rev (fn T => fn t => Lim $ mk_fun_inj T (Abs ("x", T, t))) Ts t;
   1.137 -
   1.138 -    (************** generate introduction rules for representing set **********)
   1.139 -
   1.140 -    val _ = Old_Datatype_Aux.message config "Constructing representing sets ...";
   1.141 -
   1.142 -    (* make introduction rule for a single constructor *)
   1.143 -
   1.144 -    fun make_intr s n (i, (_, cargs)) =
   1.145 -      let
   1.146 -        fun mk_prem dt (j, prems, ts) =
   1.147 -          (case Old_Datatype_Aux.strip_dtyp dt of
   1.148 -            (dts, Old_Datatype_Aux.DtRec k) =>
   1.149 -              let
   1.150 -                val Ts = map (Old_Datatype_Aux.typ_of_dtyp descr') dts;
   1.151 -                val free_t =
   1.152 -                  Old_Datatype_Aux.app_bnds (Old_Datatype_Aux.mk_Free "x" (Ts ---> Univ_elT) j)
   1.153 -                    (length Ts)
   1.154 -              in
   1.155 -                (j + 1, Logic.list_all (map (pair "x") Ts,
   1.156 -                  HOLogic.mk_Trueprop
   1.157 -                    (Free (nth rep_set_names' k, UnivT') $ free_t)) :: prems,
   1.158 -                mk_lim free_t Ts :: ts)
   1.159 -              end
   1.160 -          | _ =>
   1.161 -              let val T = Old_Datatype_Aux.typ_of_dtyp descr' dt
   1.162 -              in (j + 1, prems, (Leaf $ mk_inj T (Old_Datatype_Aux.mk_Free "x" T j)) :: ts) end);
   1.163 -
   1.164 -        val (_, prems, ts) = fold_rev mk_prem cargs (1, [], []);
   1.165 -        val concl = HOLogic.mk_Trueprop (Free (s, UnivT') $ mk_univ_inj ts n i);
   1.166 -      in Logic.list_implies (prems, concl) end;
   1.167 -
   1.168 -    val intr_ts = maps (fn ((_, (_, _, constrs)), rep_set_name) =>
   1.169 -      map (make_intr rep_set_name (length constrs))
   1.170 -        ((1 upto length constrs) ~~ constrs)) (descr' ~~ rep_set_names');
   1.171 -
   1.172 -    val ({raw_induct = rep_induct, intrs = rep_intrs, ...}, thy2) =
   1.173 -      thy1
   1.174 -      |> Sign.concealed
   1.175 -      |> Inductive.add_inductive_global
   1.176 -          {quiet_mode = #quiet config, verbose = false, alt_name = Binding.name big_rec_name,
   1.177 -           coind = false, no_elim = true, no_ind = false, skip_mono = true}
   1.178 -          (map (fn s => ((Binding.name s, UnivT'), NoSyn)) rep_set_names') []
   1.179 -          (map (fn x => (Binding.empty_atts, x)) intr_ts) []
   1.180 -      ||> Sign.restore_naming thy1;
   1.181 -
   1.182 -    (********************************* typedef ********************************)
   1.183 -
   1.184 -    val (typedefs, thy3) = thy2
   1.185 -      |> Sign.parent_path
   1.186 -      |> fold_map
   1.187 -        (fn (((name, mx), tvs), c) =>
   1.188 -          Typedef.add_typedef_global {overloaded = false} (name, tvs, mx)
   1.189 -            (Collect $ Const (c, UnivT')) NONE
   1.190 -            (fn ctxt =>
   1.191 -              resolve_tac ctxt [exI] 1 THEN
   1.192 -              resolve_tac ctxt [CollectI] 1 THEN
   1.193 -              QUIET_BREADTH_FIRST (has_fewer_prems 1)
   1.194 -              (resolve_tac ctxt rep_intrs 1)))
   1.195 -        (types_syntax ~~ tyvars ~~ take (length newTs) rep_set_names)
   1.196 -      ||> Sign.add_path big_name;
   1.197 -
   1.198 -    (*********************** definition of constructors ***********************)
   1.199 -
   1.200 -    val big_rep_name = big_name ^ "_Rep_";
   1.201 -    val rep_names' = map (fn i => big_rep_name ^ string_of_int i) (1 upto length (flat (tl descr)));
   1.202 -    val all_rep_names =
   1.203 -      map (#Rep_name o #1 o #2) typedefs @
   1.204 -      map (Sign.full_bname thy3) rep_names';
   1.205 -
   1.206 -    (* isomorphism declarations *)
   1.207 -
   1.208 -    val iso_decls = map (fn (T, s) => (Binding.name s, T --> Univ_elT, NoSyn))
   1.209 -      (oldTs ~~ rep_names');
   1.210 -
   1.211 -    (* constructor definitions *)
   1.212 -
   1.213 -    fun make_constr_def (typedef: Typedef.info) T n
   1.214 -        ((cname, cargs), (cname', mx)) (thy, defs, eqns, i) =
   1.215 -      let
   1.216 -        fun constr_arg dt (j, l_args, r_args) =
   1.217 -          let
   1.218 -            val T = Old_Datatype_Aux.typ_of_dtyp descr' dt;
   1.219 -            val free_t = Old_Datatype_Aux.mk_Free "x" T j;
   1.220 -          in
   1.221 -            (case (Old_Datatype_Aux.strip_dtyp dt, strip_type T) of
   1.222 -              ((_, Old_Datatype_Aux.DtRec m), (Us, U)) =>
   1.223 -                (j + 1, free_t :: l_args, mk_lim
   1.224 -                  (Const (nth all_rep_names m, U --> Univ_elT) $
   1.225 -                    Old_Datatype_Aux.app_bnds free_t (length Us)) Us :: r_args)
   1.226 -            | _ => (j + 1, free_t :: l_args, (Leaf $ mk_inj T free_t) :: r_args))
   1.227 -          end;
   1.228 -
   1.229 -        val (_, l_args, r_args) = fold_rev constr_arg cargs (1, [], []);
   1.230 -        val constrT = map (Old_Datatype_Aux.typ_of_dtyp descr') cargs ---> T;
   1.231 -        val ({Abs_name, Rep_name, ...}, _) = typedef;
   1.232 -        val lhs = list_comb (Const (cname, constrT), l_args);
   1.233 -        val rhs = mk_univ_inj r_args n i;
   1.234 -        val def = Logic.mk_equals (lhs, Const (Abs_name, Univ_elT --> T) $ rhs);
   1.235 -        val def_name = Thm.def_name (Long_Name.base_name cname);
   1.236 -        val eqn =
   1.237 -          HOLogic.mk_Trueprop (HOLogic.mk_eq (Const (Rep_name, T --> Univ_elT) $ lhs, rhs));
   1.238 -        val ([def_thm], thy') =
   1.239 -          thy
   1.240 -          |> Sign.add_consts [(cname', constrT, mx)]
   1.241 -          |> (Global_Theory.add_defs false o map Thm.no_attributes) [(Binding.name def_name, def)];
   1.242 -
   1.243 -      in (thy', defs @ [def_thm], eqns @ [eqn], i + 1) end;
   1.244 -
   1.245 -    (* constructor definitions for datatype *)
   1.246 -
   1.247 -    fun dt_constr_defs (((((_, (_, _, constrs)), tname), typedef: Typedef.info), T), constr_syntax)
   1.248 -        (thy, defs, eqns, rep_congs, dist_lemmas) =
   1.249 -      let
   1.250 -        val ctxt = Proof_Context.init_global thy;
   1.251 -        val _ $ (_ $ (cong_f $ _) $ _) = Thm.concl_of arg_cong;
   1.252 -        val rep_const = Thm.cterm_of ctxt (Const (#Rep_name (#1 typedef), T --> Univ_elT));
   1.253 -        val cong' = infer_instantiate ctxt [(#1 (dest_Var cong_f), rep_const)] arg_cong;
   1.254 -        val dist = infer_instantiate ctxt [(#1 (dest_Var distinct_f), rep_const)] distinct_lemma;
   1.255 -        val (thy', defs', eqns', _) =
   1.256 -          fold (make_constr_def typedef T (length constrs))
   1.257 -            (constrs ~~ constr_syntax) (Sign.add_path tname thy, defs, [], 1);
   1.258 -      in
   1.259 -        (Sign.parent_path thy', defs', eqns @ [eqns'],
   1.260 -          rep_congs @ [cong'], dist_lemmas @ [dist])
   1.261 -      end;
   1.262 -
   1.263 -    val (thy4, constr_defs, constr_rep_eqns, rep_congs, dist_lemmas) =
   1.264 -      fold dt_constr_defs
   1.265 -        (hd descr ~~ new_type_names ~~ map #2 typedefs ~~ newTs ~~ constr_syntax)
   1.266 -        (thy3 |> Sign.add_consts iso_decls |> Sign.parent_path, [], [], [], []);
   1.267 -
   1.268 -
   1.269 -    (*********** isomorphisms for new types (introduced by typedef) ***********)
   1.270 -
   1.271 -    val _ = Old_Datatype_Aux.message config "Proving isomorphism properties ...";
   1.272 -
   1.273 -    val collect_simp = rewrite_rule (Proof_Context.init_global thy4) [mk_meta_eq mem_Collect_eq];
   1.274 -
   1.275 -    val newT_iso_axms = typedefs |> map (fn (_, (_, {Abs_inverse, Rep_inverse, Rep, ...})) =>
   1.276 -      (collect_simp Abs_inverse, Rep_inverse, collect_simp Rep));
   1.277 -
   1.278 -    val newT_iso_inj_thms = typedefs |> map (fn (_, (_, {Abs_inject, Rep_inject, ...})) =>
   1.279 -      (collect_simp Abs_inject RS iffD1, Rep_inject RS iffD1));
   1.280 -
   1.281 -    (********* isomorphisms between existing types and "unfolded" types *******)
   1.282 -
   1.283 -    (*---------------------------------------------------------------------*)
   1.284 -    (* isomorphisms are defined using primrec-combinators:                 *)
   1.285 -    (* generate appropriate functions for instantiating primrec-combinator *)
   1.286 -    (*                                                                     *)
   1.287 -    (*   e.g.  Rep_dt_i = list_rec ... (%h t y. In1 (Scons (Leaf h) y))    *)
   1.288 -    (*                                                                     *)
   1.289 -    (* also generate characteristic equations for isomorphisms             *)
   1.290 -    (*                                                                     *)
   1.291 -    (*   e.g.  Rep_dt_i (cons h t) = In1 (Scons (Rep_dt_j h) (Rep_dt_i t)) *)
   1.292 -    (*---------------------------------------------------------------------*)
   1.293 -
   1.294 -    fun make_iso_def k ks n (cname, cargs) (fs, eqns, i) =
   1.295 -      let
   1.296 -        val argTs = map (Old_Datatype_Aux.typ_of_dtyp descr') cargs;
   1.297 -        val T = nth recTs k;
   1.298 -        val rep_const = Const (nth all_rep_names k, T --> Univ_elT);
   1.299 -        val constr = Const (cname, argTs ---> T);
   1.300 -
   1.301 -        fun process_arg ks' dt (i2, i2', ts, Ts) =
   1.302 -          let
   1.303 -            val T' = Old_Datatype_Aux.typ_of_dtyp descr' dt;
   1.304 -            val (Us, U) = strip_type T'
   1.305 -          in
   1.306 -            (case Old_Datatype_Aux.strip_dtyp dt of
   1.307 -              (_, Old_Datatype_Aux.DtRec j) =>
   1.308 -                if member (op =) ks' j then
   1.309 -                  (i2 + 1, i2' + 1, ts @ [mk_lim (Old_Datatype_Aux.app_bnds
   1.310 -                     (Old_Datatype_Aux.mk_Free "y" (Us ---> Univ_elT) i2') (length Us)) Us],
   1.311 -                   Ts @ [Us ---> Univ_elT])
   1.312 -                else
   1.313 -                  (i2 + 1, i2', ts @ [mk_lim
   1.314 -                     (Const (nth all_rep_names j, U --> Univ_elT) $
   1.315 -                        Old_Datatype_Aux.app_bnds
   1.316 -                          (Old_Datatype_Aux.mk_Free "x" T' i2) (length Us)) Us], Ts)
   1.317 -            | _ => (i2 + 1, i2', ts @ [Leaf $ mk_inj T' (Old_Datatype_Aux.mk_Free "x" T' i2)], Ts))
   1.318 -          end;
   1.319 -
   1.320 -        val (i2, i2', ts, Ts) = fold (process_arg ks) cargs (1, 1, [], []);
   1.321 -        val xs = map (uncurry (Old_Datatype_Aux.mk_Free "x")) (argTs ~~ (1 upto (i2 - 1)));
   1.322 -        val ys = map (uncurry (Old_Datatype_Aux.mk_Free "y")) (Ts ~~ (1 upto (i2' - 1)));
   1.323 -        val f = fold_rev lambda (xs @ ys) (mk_univ_inj ts n i);
   1.324 -
   1.325 -        val (_, _, ts', _) = fold (process_arg []) cargs (1, 1, [], []);
   1.326 -        val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
   1.327 -          (rep_const $ list_comb (constr, xs), mk_univ_inj ts' n i))
   1.328 -
   1.329 -      in (fs @ [f], eqns @ [eqn], i + 1) end;
   1.330 -
   1.331 -    (* define isomorphisms for all mutually recursive datatypes in list ds *)
   1.332 -
   1.333 -    fun make_iso_defs ds (thy, char_thms) =
   1.334 -      let
   1.335 -        val ks = map fst ds;
   1.336 -        val (_, (tname, _, _)) = hd ds;
   1.337 -        val {rec_rewrites, rec_names, ...} = the (Symtab.lookup dt_info tname);
   1.338 -
   1.339 -        fun process_dt (k, (_, _, constrs)) (fs, eqns, isos) =
   1.340 -          let
   1.341 -            val (fs', eqns', _) = fold (make_iso_def k ks (length constrs)) constrs (fs, eqns, 1);
   1.342 -            val iso = (nth recTs k, nth all_rep_names k);
   1.343 -          in (fs', eqns', isos @ [iso]) end;
   1.344 -
   1.345 -        val (fs, eqns, isos) = fold process_dt ds ([], [], []);
   1.346 -        val fTs = map fastype_of fs;
   1.347 -        val defs =
   1.348 -          map (fn (rec_name, (T, iso_name)) =>
   1.349 -            (Binding.name (Thm.def_name (Long_Name.base_name iso_name)),
   1.350 -              Logic.mk_equals (Const (iso_name, T --> Univ_elT),
   1.351 -                list_comb (Const (rec_name, fTs @ [T] ---> Univ_elT), fs)))) (rec_names ~~ isos);
   1.352 -        val (def_thms, thy') =
   1.353 -          (Global_Theory.add_defs false o map Thm.no_attributes) defs thy;
   1.354 -
   1.355 -        (* prove characteristic equations *)
   1.356 -
   1.357 -        val rewrites = def_thms @ map mk_meta_eq rec_rewrites;
   1.358 -        val char_thms' =
   1.359 -          map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn
   1.360 -            (fn {context = ctxt, ...} =>
   1.361 -              EVERY [rewrite_goals_tac ctxt rewrites, resolve_tac ctxt [refl] 1])) eqns;
   1.362 -
   1.363 -      in (thy', char_thms' @ char_thms) end;
   1.364 -
   1.365 -    val (thy5, iso_char_thms) =
   1.366 -      fold_rev make_iso_defs (tl descr) (Sign.add_path big_name thy4, []);
   1.367 -
   1.368 -    (* prove isomorphism properties *)
   1.369 -
   1.370 -    fun mk_funs_inv thy thm =
   1.371 -      let
   1.372 -        val prop = Thm.prop_of thm;
   1.373 -        val _ $ (_ $ ((S as Const (_, Type (_, [U, _]))) $ _ )) $
   1.374 -          (_ $ (_ $ (r $ (a $ _)) $ _)) = Type.legacy_freeze prop;
   1.375 -        val used = Term.add_tfree_names a [];
   1.376 -
   1.377 -        fun mk_thm i =
   1.378 -          let
   1.379 -            val Ts = map (TFree o rpair @{sort type}) (Name.variant_list used (replicate i "'t"));
   1.380 -            val f = Free ("f", Ts ---> U);
   1.381 -          in
   1.382 -            Goal.prove_sorry_global thy [] []
   1.383 -              (Logic.mk_implies
   1.384 -                (HOLogic.mk_Trueprop (HOLogic.list_all
   1.385 -                   (map (pair "x") Ts, S $ Old_Datatype_Aux.app_bnds f i)),
   1.386 -                 HOLogic.mk_Trueprop (HOLogic.mk_eq (fold_rev (Term.abs o pair "x") Ts
   1.387 -                   (r $ (a $ Old_Datatype_Aux.app_bnds f i)), f))))
   1.388 -              (fn {context = ctxt, ...} =>
   1.389 -                EVERY [REPEAT_DETERM_N i (resolve_tac ctxt @{thms ext} 1),
   1.390 -                 REPEAT (eresolve_tac ctxt [allE] 1),
   1.391 -                 resolve_tac ctxt [thm] 1,
   1.392 -                 assume_tac ctxt 1])
   1.393 -          end
   1.394 -      in map (fn r => r RS subst) (thm :: map mk_thm arities) end;
   1.395 -
   1.396 -    (* prove  inj Rep_dt_i  and  Rep_dt_i x : rep_set_dt_i *)
   1.397 -
   1.398 -    val fun_congs =
   1.399 -      map (fn T => make_elim (Thm.instantiate' [SOME (Thm.global_ctyp_of thy5 T)] [] fun_cong)) branchTs;
   1.400 -
   1.401 -    fun prove_iso_thms ds (inj_thms, elem_thms) =
   1.402 -      let
   1.403 -        val (_, (tname, _, _)) = hd ds;
   1.404 -        val induct = #induct (the (Symtab.lookup dt_info tname));
   1.405 -
   1.406 -        fun mk_ind_concl (i, _) =
   1.407 -          let
   1.408 -            val T = nth recTs i;
   1.409 -            val Rep_t = Const (nth all_rep_names i, T --> Univ_elT);
   1.410 -            val rep_set_name = nth rep_set_names i;
   1.411 -            val concl1 =
   1.412 -              HOLogic.all_const T $ Abs ("y", T, HOLogic.imp $
   1.413 -                HOLogic.mk_eq (Rep_t $ Old_Datatype_Aux.mk_Free "x" T i, Rep_t $ Bound 0) $
   1.414 -                  HOLogic.mk_eq (Old_Datatype_Aux.mk_Free "x" T i, Bound 0));
   1.415 -            val concl2 = Const (rep_set_name, UnivT') $ (Rep_t $ Old_Datatype_Aux.mk_Free "x" T i);
   1.416 -          in (concl1, concl2) end;
   1.417 -
   1.418 -        val (ind_concl1, ind_concl2) = split_list (map mk_ind_concl ds);
   1.419 -
   1.420 -        val rewrites = map mk_meta_eq iso_char_thms;
   1.421 -        val inj_thms' = map snd newT_iso_inj_thms @ map (fn r => r RS @{thm injD}) inj_thms;
   1.422 -
   1.423 -        val inj_thm =
   1.424 -          Goal.prove_sorry_global thy5 [] []
   1.425 -            (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj ind_concl1))
   1.426 -            (fn {context = ctxt, ...} => EVERY
   1.427 -              [(Old_Datatype_Aux.ind_tac ctxt induct [] THEN_ALL_NEW
   1.428 -                  Object_Logic.atomize_prems_tac ctxt) 1,
   1.429 -               REPEAT (EVERY
   1.430 -                 [resolve_tac ctxt [allI] 1, resolve_tac ctxt [impI] 1,
   1.431 -                  Old_Datatype_Aux.exh_tac ctxt (exh_thm_of dt_info) 1,
   1.432 -                  REPEAT (EVERY
   1.433 -                    [hyp_subst_tac ctxt 1,
   1.434 -                     rewrite_goals_tac ctxt rewrites,
   1.435 -                     REPEAT (dresolve_tac ctxt [In0_inject, In1_inject] 1),
   1.436 -                     (eresolve_tac ctxt [In0_not_In1 RS notE, In1_not_In0 RS notE] 1)
   1.437 -                     ORELSE (EVERY
   1.438 -                       [REPEAT (eresolve_tac ctxt (Scons_inject ::
   1.439 -                          map make_elim [Leaf_inject, Inl_inject, Inr_inject]) 1),
   1.440 -                        REPEAT (cong_tac ctxt 1), resolve_tac ctxt [refl] 1,
   1.441 -                        REPEAT (assume_tac ctxt 1 ORELSE (EVERY
   1.442 -                          [REPEAT (resolve_tac ctxt @{thms ext} 1),
   1.443 -                           REPEAT (eresolve_tac ctxt (mp :: allE ::
   1.444 -                             map make_elim (Suml_inject :: Sumr_inject ::
   1.445 -                               Lim_inject :: inj_thms') @ fun_congs) 1),
   1.446 -                           assume_tac ctxt 1]))])])])]);
   1.447 -
   1.448 -        val inj_thms'' = map (fn r => r RS datatype_injI) (Old_Datatype_Aux.split_conj_thm inj_thm);
   1.449 -
   1.450 -        val elem_thm =
   1.451 -          Goal.prove_sorry_global thy5 [] []
   1.452 -            (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj ind_concl2))
   1.453 -            (fn {context = ctxt, ...} =>
   1.454 -              EVERY [
   1.455 -                (Old_Datatype_Aux.ind_tac ctxt induct [] THEN_ALL_NEW
   1.456 -                  Object_Logic.atomize_prems_tac ctxt) 1,
   1.457 -                rewrite_goals_tac ctxt rewrites,
   1.458 -                REPEAT ((resolve_tac ctxt rep_intrs THEN_ALL_NEW
   1.459 -                  ((REPEAT o eresolve_tac ctxt [allE]) THEN' ares_tac ctxt elem_thms)) 1)]);
   1.460 -
   1.461 -      in (inj_thms'' @ inj_thms, elem_thms @ Old_Datatype_Aux.split_conj_thm elem_thm) end;
   1.462 -
   1.463 -    val (iso_inj_thms_unfolded, iso_elem_thms) =
   1.464 -      fold_rev prove_iso_thms (tl descr) ([], map #3 newT_iso_axms);
   1.465 -    val iso_inj_thms =
   1.466 -      map snd newT_iso_inj_thms @ map (fn r => r RS @{thm injD}) iso_inj_thms_unfolded;
   1.467 -
   1.468 -    (* prove  rep_set_dt_i x --> x : range Rep_dt_i *)
   1.469 -
   1.470 -    fun mk_iso_t (((set_name, iso_name), i), T) =
   1.471 -      let val isoT = T --> Univ_elT in
   1.472 -        HOLogic.imp $
   1.473 -          (Const (set_name, UnivT') $ Old_Datatype_Aux.mk_Free "x" Univ_elT i) $
   1.474 -            (if i < length newTs then @{term True}
   1.475 -             else HOLogic.mk_mem (Old_Datatype_Aux.mk_Free "x" Univ_elT i,
   1.476 -               Const (@{const_name image}, isoT --> HOLogic.mk_setT T --> UnivT) $
   1.477 -                 Const (iso_name, isoT) $ Const (@{const_abbrev UNIV}, HOLogic.mk_setT T)))
   1.478 -      end;
   1.479 -
   1.480 -    val iso_t = HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj (map mk_iso_t
   1.481 -      (rep_set_names ~~ all_rep_names ~~ (0 upto (length descr' - 1)) ~~ recTs)));
   1.482 -
   1.483 -    (* all the theorems are proved by one single simultaneous induction *)
   1.484 -
   1.485 -    val range_eqs = map (fn r => mk_meta_eq (r RS @{thm range_ex1_eq})) iso_inj_thms_unfolded;
   1.486 -
   1.487 -    val iso_thms =
   1.488 -      if length descr = 1 then []
   1.489 -      else
   1.490 -        drop (length newTs) (Old_Datatype_Aux.split_conj_thm
   1.491 -          (Goal.prove_sorry_global thy5 [] [] iso_t (fn {context = ctxt, ...} => EVERY
   1.492 -             [(Old_Datatype_Aux.ind_tac ctxt rep_induct [] THEN_ALL_NEW
   1.493 -                 Object_Logic.atomize_prems_tac ctxt) 1,
   1.494 -              REPEAT (resolve_tac ctxt [TrueI] 1),
   1.495 -              rewrite_goals_tac ctxt (mk_meta_eq @{thm choice_eq} ::
   1.496 -                Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs),
   1.497 -              rewrite_goals_tac ctxt (map Thm.symmetric range_eqs),
   1.498 -              REPEAT (EVERY
   1.499 -                [REPEAT (eresolve_tac ctxt ([rangeE, @{thm ex1_implies_ex} RS exE] @
   1.500 -                   maps (mk_funs_inv thy5 o #1) newT_iso_axms) 1),
   1.501 -                 TRY (hyp_subst_tac ctxt 1),
   1.502 -                 resolve_tac ctxt [sym RS range_eqI] 1,
   1.503 -                 resolve_tac ctxt iso_char_thms 1])])));
   1.504 -
   1.505 -    val Abs_inverse_thms' =
   1.506 -      map #1 newT_iso_axms @
   1.507 -      map2 (fn r_inj => fn r => @{thm f_the_inv_into_f} OF [r_inj, r RS mp])
   1.508 -        iso_inj_thms_unfolded iso_thms;
   1.509 -
   1.510 -    val Abs_inverse_thms = maps (mk_funs_inv thy5) Abs_inverse_thms';
   1.511 -
   1.512 -    (******************* freeness theorems for constructors *******************)
   1.513 -
   1.514 -    val _ = Old_Datatype_Aux.message config "Proving freeness of constructors ...";
   1.515 -
   1.516 -    (* prove theorem  Rep_i (Constr_j ...) = Inj_j ...  *)
   1.517 -
   1.518 -    fun prove_constr_rep_thm eqn =
   1.519 -      let
   1.520 -        val inj_thms = map fst newT_iso_inj_thms;
   1.521 -        val rewrites = @{thm o_def} :: constr_defs @ map (mk_meta_eq o #2) newT_iso_axms;
   1.522 -      in
   1.523 -        Goal.prove_sorry_global thy5 [] [] eqn
   1.524 -        (fn {context = ctxt, ...} => EVERY
   1.525 -          [resolve_tac ctxt inj_thms 1,
   1.526 -           rewrite_goals_tac ctxt rewrites,
   1.527 -           resolve_tac ctxt [refl] 3,
   1.528 -           resolve_tac ctxt rep_intrs 2,
   1.529 -           REPEAT (resolve_tac ctxt iso_elem_thms 1)])
   1.530 -      end;
   1.531 -
   1.532 -    (*--------------------------------------------------------------*)
   1.533 -    (* constr_rep_thms and rep_congs are used to prove distinctness *)
   1.534 -    (* of constructors.                                             *)
   1.535 -    (*--------------------------------------------------------------*)
   1.536 -
   1.537 -    val constr_rep_thms = map (map prove_constr_rep_thm) constr_rep_eqns;
   1.538 -
   1.539 -    val dist_rewrites =
   1.540 -      map (fn (rep_thms, dist_lemma) =>
   1.541 -        dist_lemma :: (rep_thms @ [In0_eq, In1_eq, In0_not_In1, In1_not_In0]))
   1.542 -          (constr_rep_thms ~~ dist_lemmas);
   1.543 -
   1.544 -    fun prove_distinct_thms dist_rewrites' =
   1.545 -      let
   1.546 -        fun prove [] = []
   1.547 -          | prove (t :: ts) =
   1.548 -              let
   1.549 -                val dist_thm = Goal.prove_sorry_global thy5 [] [] t (fn {context = ctxt, ...} =>
   1.550 -                  EVERY [simp_tac (put_simpset HOL_ss ctxt addsimps dist_rewrites') 1])
   1.551 -              in dist_thm :: Drule.zero_var_indexes (dist_thm RS not_sym) :: prove ts end;
   1.552 -      in prove end;
   1.553 -
   1.554 -    val distinct_thms =
   1.555 -      map2 (prove_distinct_thms) dist_rewrites (Old_Datatype_Prop.make_distincts descr);
   1.556 -
   1.557 -    (* prove injectivity of constructors *)
   1.558 -
   1.559 -    fun prove_constr_inj_thm rep_thms t =
   1.560 -      let
   1.561 -        val inj_thms = Scons_inject ::
   1.562 -          map make_elim
   1.563 -            (iso_inj_thms @
   1.564 -              [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject,
   1.565 -               Lim_inject, Suml_inject, Sumr_inject])
   1.566 -      in
   1.567 -        Goal.prove_sorry_global thy5 [] [] t
   1.568 -          (fn {context = ctxt, ...} => EVERY
   1.569 -            [resolve_tac ctxt [iffI] 1,
   1.570 -             REPEAT (eresolve_tac ctxt [conjE] 2), hyp_subst_tac ctxt 2,
   1.571 -             resolve_tac ctxt [refl] 2,
   1.572 -             dresolve_tac ctxt rep_congs 1,
   1.573 -             dresolve_tac ctxt @{thms box_equals} 1,
   1.574 -             REPEAT (resolve_tac ctxt rep_thms 1),
   1.575 -             REPEAT (eresolve_tac ctxt inj_thms 1),
   1.576 -             REPEAT (ares_tac ctxt [conjI] 1 ORELSE (EVERY [REPEAT (resolve_tac ctxt @{thms ext} 1),
   1.577 -               REPEAT (eresolve_tac ctxt (make_elim fun_cong :: inj_thms) 1),
   1.578 -               assume_tac ctxt 1]))])
   1.579 -      end;
   1.580 -
   1.581 -    val constr_inject =
   1.582 -      map (fn (ts, thms) => map (prove_constr_inj_thm thms) ts)
   1.583 -        (Old_Datatype_Prop.make_injs descr ~~ constr_rep_thms);
   1.584 -
   1.585 -    val ((constr_inject', distinct_thms'), thy6) =
   1.586 -      thy5
   1.587 -      |> Sign.parent_path
   1.588 -      |> Old_Datatype_Aux.store_thmss "inject" new_type_names constr_inject
   1.589 -      ||>> Old_Datatype_Aux.store_thmss "distinct" new_type_names distinct_thms;
   1.590 -
   1.591 -    (*************************** induction theorem ****************************)
   1.592 -
   1.593 -    val _ = Old_Datatype_Aux.message config "Proving induction rule for datatypes ...";
   1.594 -
   1.595 -    val Rep_inverse_thms =
   1.596 -      map (fn (_, iso, _) => iso RS subst) newT_iso_axms @
   1.597 -      map (fn r => r RS @{thm the_inv_f_f} RS subst) iso_inj_thms_unfolded;
   1.598 -    val Rep_inverse_thms' = map (fn r => r RS @{thm the_inv_f_f}) iso_inj_thms_unfolded;
   1.599 -
   1.600 -    fun mk_indrule_lemma (i, _) T =
   1.601 -      let
   1.602 -        val Rep_t = Const (nth all_rep_names i, T --> Univ_elT) $ Old_Datatype_Aux.mk_Free "x" T i;
   1.603 -        val Abs_t =
   1.604 -          if i < length newTs then
   1.605 -            Const (#Abs_name (#1 (#2 (nth typedefs i))), Univ_elT --> T)
   1.606 -          else
   1.607 -            Const (@{const_name the_inv_into},
   1.608 -              [HOLogic.mk_setT T, T --> Univ_elT, Univ_elT] ---> T) $
   1.609 -            HOLogic.mk_UNIV T $ Const (nth all_rep_names i, T --> Univ_elT);
   1.610 -        val prem =
   1.611 -          HOLogic.imp $
   1.612 -            (Const (nth rep_set_names i, UnivT') $ Rep_t) $
   1.613 -              (Old_Datatype_Aux.mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ (Abs_t $ Rep_t));
   1.614 -        val concl =
   1.615 -          Old_Datatype_Aux.mk_Free "P" (T --> HOLogic.boolT) (i + 1) $
   1.616 -            Old_Datatype_Aux.mk_Free "x" T i;
   1.617 -      in (prem, concl) end;
   1.618 -
   1.619 -    val (indrule_lemma_prems, indrule_lemma_concls) =
   1.620 -      split_list (map2 mk_indrule_lemma descr' recTs);
   1.621 -
   1.622 -    val indrule_lemma =
   1.623 -      Goal.prove_sorry_global thy6 [] []
   1.624 -        (Logic.mk_implies
   1.625 -          (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_prems),
   1.626 -           HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_concls)))
   1.627 -        (fn {context = ctxt, ...} =>
   1.628 -          EVERY
   1.629 -           [REPEAT (eresolve_tac ctxt [conjE] 1),
   1.630 -            REPEAT (EVERY
   1.631 -              [TRY (resolve_tac ctxt [conjI] 1), resolve_tac ctxt Rep_inverse_thms 1,
   1.632 -               eresolve_tac ctxt [mp] 1, resolve_tac ctxt iso_elem_thms 1])]);
   1.633 -
   1.634 -    val Ps = map head_of (HOLogic.dest_conj (HOLogic.dest_Trueprop (Thm.concl_of indrule_lemma)));
   1.635 -    val frees =
   1.636 -      if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))]
   1.637 -      else map (Free o apfst fst o dest_Var) Ps;
   1.638 -
   1.639 -    val dt_induct_prop = Old_Datatype_Prop.make_ind descr;
   1.640 -    val dt_induct =
   1.641 -      Goal.prove_sorry_global thy6 []
   1.642 -      (Logic.strip_imp_prems dt_induct_prop)
   1.643 -      (Logic.strip_imp_concl dt_induct_prop)
   1.644 -      (fn {context = ctxt, prems, ...} =>
   1.645 -        let
   1.646 -          val indrule_lemma' =
   1.647 -            infer_instantiate ctxt
   1.648 -              (map (#1 o dest_Var) Ps ~~ map (Thm.cterm_of ctxt) frees) indrule_lemma;
   1.649 -        in
   1.650 -          EVERY
   1.651 -            [resolve_tac ctxt [indrule_lemma'] 1,
   1.652 -             (Old_Datatype_Aux.ind_tac ctxt rep_induct [] THEN_ALL_NEW
   1.653 -                Object_Logic.atomize_prems_tac ctxt) 1,
   1.654 -             EVERY (map (fn (prem, r) => (EVERY
   1.655 -               [REPEAT (eresolve_tac ctxt Abs_inverse_thms 1),
   1.656 -                simp_tac (put_simpset HOL_basic_ss ctxt
   1.657 -                  addsimps (Thm.symmetric r :: Rep_inverse_thms')) 1,
   1.658 -                DEPTH_SOLVE_1 (ares_tac ctxt [prem] 1 ORELSE eresolve_tac ctxt [allE] 1)]))
   1.659 -                    (prems ~~ (constr_defs @ map mk_meta_eq iso_char_thms)))]
   1.660 -        end);
   1.661 -
   1.662 -    val ([(_, [dt_induct'])], thy7) =
   1.663 -      thy6
   1.664 -      |> Global_Theory.note_thmss ""
   1.665 -        [((Binding.qualify true big_name (Binding.name "induct"), [case_names_induct]),
   1.666 -          [([dt_induct], [])])];
   1.667 -  in
   1.668 -    ((constr_inject', distinct_thms', dt_induct'), thy7)
   1.669 -  end;
   1.670 -
   1.671 -
   1.672 -
   1.673 -(** datatype definition **)
   1.674 -
   1.675 -(* specifications *)
   1.676  
   1.677  type spec_cmd =
   1.678    (binding * (string * string option) list * mixfix) * (binding * string list * mixfix) list;
   1.679  
   1.680 -local
   1.681 -
   1.682  fun parse_spec ctxt ((b, args, mx), constrs) =
   1.683    ((b, map (apsnd (Typedecl.read_constraint ctxt)) args, mx),
   1.684      constrs |> map (fn (c, Ts, mx') => (c, map (Syntax.parse_typ ctxt) Ts, mx')));
   1.685 @@ -709,90 +53,9 @@
   1.686      val specs = check_specs ctxt (map (parse ctxt) raw_specs);
   1.687    in (specs, ctxt) end;
   1.688  
   1.689 -in
   1.690 -
   1.691  val read_specs = prep_specs parse_spec;
   1.692  val check_specs = prep_specs (K I);
   1.693  
   1.694 -end;
   1.695 -
   1.696 -
   1.697 -(* main commands *)
   1.698 -
   1.699 -fun gen_add_datatype prep_specs config raw_specs thy =
   1.700 -  let
   1.701 -    val (dts, spec_ctxt) = prep_specs raw_specs thy;
   1.702 -    val ((_, tyvars, _), _) :: _ = dts;
   1.703 -    val string_of_tyvar = Syntax.string_of_typ spec_ctxt o TFree;
   1.704 -
   1.705 -    val (new_dts, types_syntax) = dts |> map (fn ((tname, tvs, mx), _) =>
   1.706 -      let val full_tname = Sign.full_name thy tname in
   1.707 -        (case duplicates (op =) tvs of
   1.708 -          [] =>
   1.709 -            if eq_set (op =) (tyvars, tvs) then ((full_tname, tvs), (tname, mx))
   1.710 -            else error "Mutually recursive datatypes must have same type parameters"
   1.711 -        | dups =>
   1.712 -            error ("Duplicate parameter(s) for datatype " ^ Binding.print tname ^
   1.713 -              " : " ^ commas (map string_of_tyvar dups)))
   1.714 -      end) |> split_list;
   1.715 -    val dt_names = map fst new_dts;
   1.716 -
   1.717 -    val _ =
   1.718 -      (case duplicates (op =) (map fst new_dts) of
   1.719 -        [] => ()
   1.720 -      | dups => error ("Duplicate datatypes: " ^ commas_quote dups));
   1.721 -
   1.722 -    fun prep_dt_spec ((tname, tvs, _), constrs) (dts', constr_syntax, i) =
   1.723 -      let
   1.724 -        fun prep_constr (cname, cargs, mx) (constrs, constr_syntax') =
   1.725 -          let
   1.726 -            val _ =
   1.727 -              (case subtract (op =) tvs (fold Term.add_tfreesT cargs []) of
   1.728 -                [] => ()
   1.729 -              | vs => error ("Extra type variables on rhs: " ^ commas (map string_of_tyvar vs)));
   1.730 -            val c = Sign.full_name_path thy (Binding.name_of tname) cname;
   1.731 -          in
   1.732 -            (constrs @ [(c, map (Old_Datatype_Aux.dtyp_of_typ new_dts) cargs)],
   1.733 -              constr_syntax' @ [(cname, mx)])
   1.734 -          end handle ERROR msg =>
   1.735 -            cat_error msg ("The error above occurred in constructor " ^ Binding.print cname ^
   1.736 -              " of datatype " ^ Binding.print tname);
   1.737 -
   1.738 -        val (constrs', constr_syntax') = fold prep_constr constrs ([], []);
   1.739 -      in
   1.740 -        (case duplicates (op =) (map fst constrs') of
   1.741 -          [] =>
   1.742 -            (dts' @ [(i, (Sign.full_name thy tname, map Old_Datatype_Aux.DtTFree tvs, constrs'))],
   1.743 -              constr_syntax @ [constr_syntax'], i + 1)
   1.744 -        | dups =>
   1.745 -            error ("Duplicate constructors " ^ commas_quote dups ^
   1.746 -              " in datatype " ^ Binding.print tname))
   1.747 -      end;
   1.748 -
   1.749 -    val (dts', constr_syntax, i) = fold prep_dt_spec dts ([], [], 0);
   1.750 -
   1.751 -    val dt_info = Old_Datatype_Data.get_all thy;
   1.752 -    val (descr, _) = Old_Datatype_Aux.unfold_datatypes spec_ctxt dts' dt_info dts' i;
   1.753 -    val _ =
   1.754 -      Old_Datatype_Aux.check_nonempty descr
   1.755 -        handle (exn as Old_Datatype_Aux.Datatype_Empty s) =>
   1.756 -          if #strict config then error ("Nonemptiness check failed for datatype " ^ quote s)
   1.757 -          else Exn.reraise exn;
   1.758 -
   1.759 -    val _ =
   1.760 -      Old_Datatype_Aux.message config
   1.761 -        ("Constructing datatype(s) " ^ commas_quote (map (Binding.name_of o #1 o #1) dts));
   1.762 -  in
   1.763 -    thy
   1.764 -    |> representation_proofs config dt_info descr types_syntax constr_syntax
   1.765 -      (Old_Datatype_Data.mk_case_names_induct (flat descr))
   1.766 -    |-> (fn (inject, distinct, induct) =>
   1.767 -      Old_Rep_Datatype.derive_datatype_props config dt_names descr induct inject distinct)
   1.768 -  end;
   1.769 -
   1.770 -val add_datatype = gen_add_datatype check_specs;
   1.771 -val add_datatype_cmd = gen_add_datatype read_specs;
   1.772 -
   1.773  open Old_Datatype_Aux;
   1.774  
   1.775  end;