212 fun not_mutually_recursive ss = |
212 fun not_mutually_recursive ss = |
213 error ("{" ^ commas ss ^ "} is not a complete set of mutually recursive datatypes"); |
213 error ("{" ^ commas ss ^ "} is not a complete set of mutually recursive datatypes"); |
214 |
214 |
215 fun checked_fp_sugar_of s = |
215 fun checked_fp_sugar_of s = |
216 (case fp_sugar_of lthy s of |
216 (case fp_sugar_of lthy s of |
217 SOME (fp_sugar as {fp, ...}) => |
217 SOME (fp_sugar as {fp, fp_co_induct_sugar = SOME _, ...}) => |
218 if member (op =) prefs Include_GFPs orelse fp = Least_FP then fp_sugar else not_datatype s |
218 if member (op =) prefs Include_GFPs orelse fp = Least_FP then fp_sugar else not_datatype s |
219 | NONE => not_datatype s); |
219 | _ => 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 as fpT_name1 :: _ = map (fst o dest_Type) fpTs0; |
224 val fpT_names as fpT_name1 :: _ = map (fst o dest_Type) fpTs0; |
297 val substAT = Term.typ_subst_atomic (var_As ~~ As); |
297 val substAT = Term.typ_subst_atomic (var_As ~~ As); |
298 |
298 |
299 val Xs' = map #X fp_sugars'; |
299 val Xs' = map #X fp_sugars'; |
300 val ctrXs_Tsss' = map (map (map substAT) o #ctrXs_Tss o #fp_ctr_sugar) fp_sugars'; |
300 val ctrXs_Tsss' = map (map (map substAT) o #ctrXs_Tss o #fp_ctr_sugar) fp_sugars'; |
301 val ctrss' = map2 mk_ctr_of fp_sugars' fpTs'; |
301 val ctrss' = map2 mk_ctr_of fp_sugars' fpTs'; |
302 val {fp_co_induct_sugar = {common_co_inducts = induct :: _, ...}, ...} :: _ = fp_sugars'; |
302 val {fp_co_induct_sugar = SOME {common_co_inducts = induct :: _, ...}, ...} :: _ = fp_sugars'; |
303 val inducts = map (hd o #co_inducts o #fp_co_induct_sugar) fp_sugars'; |
303 val inducts = map (hd o #co_inducts o the o #fp_co_induct_sugar) fp_sugars'; |
304 val recs = map (#co_rec o #fp_co_induct_sugar) fp_sugars'; |
304 val recs = map (#co_rec o the o #fp_co_induct_sugar) fp_sugars'; |
305 val rec_thmss = map (#co_rec_thms o #fp_co_induct_sugar) fp_sugars'; |
305 val rec_thmss = map (#co_rec_thms o the o #fp_co_induct_sugar) fp_sugars'; |
306 |
306 |
307 fun is_nested_rec_type (Type (@{type_name fun}, [_, T])) = member (op =) Xs' (body_type T) |
307 fun is_nested_rec_type (Type (@{type_name fun}, [_, T])) = member (op =) Xs' (body_type T) |
308 | is_nested_rec_type _ = false; |
308 | is_nested_rec_type _ = false; |
309 |
309 |
310 val ((lfp_sugar_thms'', (inducts', induct', recs', rec'_thmss)), lthy'') = |
310 val ((lfp_sugar_thms'', (inducts', induct', recs', rec'_thmss)), lthy'') = |