src/HOL/Tools/BNF/bnf_lfp_compat.ML
changeset 63732 622b54bbe8d4
parent 63719 9084d77f1119
child 63859 dca6fabd8060
equal deleted inserted replaced
63731:9f906a2eb0e7 63732:622b54bbe8d4
   219       | NONE => not_datatype s);
   219       | NONE => not_datatype s);
   220 
   220 
   221     val fpTs0 as Type (_, var_As) :: _ =
   221     val fpTs0 as Type (_, var_As) :: _ =
   222       map (#T o checked_fp_sugar_of o fst o dest_Type)
   222       map (#T o checked_fp_sugar_of o fst o dest_Type)
   223         (#Ts (#fp_res (checked_fp_sugar_of (hd fpT_names0))));
   223         (#Ts (#fp_res (checked_fp_sugar_of (hd fpT_names0))));
   224     val fpT_names = map (fst o dest_Type) fpTs0;
   224     val fpT_names as fpT_name1 :: _ = map (fst o dest_Type) fpTs0;
   225 
   225 
   226     val _ = check_names (op =) (fpT_names0, fpT_names) orelse not_mutually_recursive fpT_names0;
   226     val _ = check_names (op =) (fpT_names0, fpT_names) orelse not_mutually_recursive fpT_names0;
   227 
   227 
   228     val (As_names, _) = Variable.variant_fixes (map (fn TVar ((s, _), _) => s) var_As) lthy;
   228     val (As_names, _) = Variable.variant_fixes (map (fn TVar ((s, _), _) => s) var_As) lthy;
   229     val As = map2 (fn s => fn TVar (_, S) => TFree (s, S)) As_names var_As;
   229     val As = map2 (fn s => fn TVar (_, S) => TFree (s, S)) As_names var_As;
   235 
   235 
   236     fun mk_ctr_descr Ts = mk_ctr Ts #> dest_Const ##> (binder_types #> map mk_dtyp);
   236     fun mk_ctr_descr Ts = mk_ctr Ts #> dest_Const ##> (binder_types #> map mk_dtyp);
   237     fun mk_typ_descr index (Type (T_name, Ts)) ({ctrs, ...} : ctr_sugar) =
   237     fun mk_typ_descr index (Type (T_name, Ts)) ({ctrs, ...} : ctr_sugar) =
   238       (index, (T_name, map mk_dtyp Ts, map (mk_ctr_descr Ts) ctrs));
   238       (index, (T_name, map mk_dtyp Ts, map (mk_ctr_descr Ts) ctrs));
   239 
   239 
   240     val fp_ctr_sugars = map (#ctr_sugar o #fp_ctr_sugar o checked_fp_sugar_of) fpT_names;
   240     val fp_sugars as {fp, ...} :: _ = map checked_fp_sugar_of fpT_names;
       
   241     val fp_ctr_sugars = map (#ctr_sugar o #fp_ctr_sugar) fp_sugars;
   241     val orig_descr = @{map 3} mk_typ_descr (0 upto nn_fp - 1) fpTs fp_ctr_sugars;
   242     val orig_descr = @{map 3} mk_typ_descr (0 upto nn_fp - 1) fpTs fp_ctr_sugars;
   242     val all_infos = Old_Datatype_Data.get_all thy;
   243     val all_infos = Old_Datatype_Data.get_all thy;
   243     val (orig_descr' :: nested_descrs) =
   244     val (orig_descr' :: nested_descrs) =
   244       if member (op =) prefs Keep_Nesting then [orig_descr]
   245       if member (op =) prefs Keep_Nesting then [orig_descr]
   245       else fst (Old_Datatype_Aux.unfold_datatypes lthy orig_descr all_infos orig_descr nn_fp);
   246       else fst (Old_Datatype_Aux.unfold_datatypes lthy orig_descr all_infos orig_descr nn_fp);
   308 
   309 
   309     val ((lfp_sugar_thms'', (inducts', induct', recs', rec'_thmss)), lthy'') =
   310     val ((lfp_sugar_thms'', (inducts', induct', recs', rec'_thmss)), lthy'') =
   310       if member (op =) prefs Keep_Nesting orelse
   311       if member (op =) prefs Keep_Nesting orelse
   311          not (exists (exists (exists is_nested_rec_type)) ctrXs_Tsss') then
   312          not (exists (exists (exists is_nested_rec_type)) ctrXs_Tsss') then
   312         ((lfp_sugar_thms', (inducts, induct, recs, rec_thmss)), lthy')
   313         ((lfp_sugar_thms', (inducts, induct, recs, rec_thmss)), lthy')
   313       else
   314       else if fp = Least_FP then
   314         define_split_rec_derive_induct_rec_thms Xs' fpTs' ctrXs_Tsss' ctrss' inducts induct recs
   315         define_split_rec_derive_induct_rec_thms Xs' fpTs' ctrXs_Tsss' ctrss' inducts induct recs
   315           rec_thmss lthy'
   316           rec_thmss lthy'
   316         |>> `(fn (inducts', induct', _, rec'_thmss) =>
   317         |>> `(fn (inducts', induct', _, rec'_thmss) =>
   317           SOME ((inducts', induct', mk_induct_attrs ctrss'), (rec'_thmss, [])));
   318           SOME ((inducts', induct', mk_induct_attrs ctrss'), (rec'_thmss, [])))
       
   319       else
       
   320         not_datatype fpT_name1;
   318 
   321 
   319     val rec'_names = map (fst o dest_Const) recs';
   322     val rec'_names = map (fst o dest_Const) recs';
   320     val rec'_thms = flat rec'_thmss;
   323     val rec'_thms = flat rec'_thmss;
   321 
   324 
   322     fun mk_info (kk, {T = Type (T_name0, _), fp_ctr_sugar = {ctr_sugar = {casex, exhaust, nchotomy,
   325     fun mk_info (kk, {T = Type (T_name0, _), fp_ctr_sugar = {ctr_sugar = {casex, exhaust, nchotomy,