1101 fun eq_fpT_check (T as Type (s, Us)) (Type (s', Us')) = |
1102 fun eq_fpT_check (T as Type (s, Us)) (Type (s', Us')) = |
1102 s = s' andalso (Us = Us' orelse error ("Illegal occurrence of recursive type " ^ |
1103 s = s' andalso (Us = Us' orelse error ("Illegal occurrence of recursive type " ^ |
1103 quote (Syntax.string_of_typ fake_lthy T))) |
1104 quote (Syntax.string_of_typ fake_lthy T))) |
1104 | eq_fpT_check _ _ = false; |
1105 | eq_fpT_check _ _ = false; |
1105 |
1106 |
1106 fun freeze_fp (T as Type (s, Us)) = |
1107 fun freeze_fp (T as Type (s, Ts)) = |
1107 (case find_index (eq_fpT_check T) fake_Ts of |
1108 (case find_index (eq_fpT_check T) fake_Ts of |
1108 ~1 => Type (s, map freeze_fp Us) |
1109 ~1 => Type (s, map freeze_fp Ts) |
1109 | kk => nth Xs kk) |
1110 | kk => nth Xs kk) |
1110 | freeze_fp T = T; |
1111 | freeze_fp T = T; |
|
1112 |
|
1113 val unfreeze_fp = Term.typ_subst_atomic (Xs ~~ fake_Ts); |
1111 |
1114 |
1112 val ctrXs_Tsss = map (map (map freeze_fp)) fake_ctr_Tsss; |
1115 val ctrXs_Tsss = map (map (map freeze_fp)) fake_ctr_Tsss; |
1113 val ctrXs_sum_prod_Ts = map (mk_sumTN_balanced o map HOLogic.mk_tupleT) ctrXs_Tsss; |
1116 val ctrXs_sum_prod_Ts = map (mk_sumTN_balanced o map HOLogic.mk_tupleT) ctrXs_Tsss; |
1114 |
1117 |
1115 val fp_eqs = |
1118 val fp_eqs = |
1117 |
1120 |
1118 val (pre_bnfs, (fp_res as {bnfs = fp_bnfs as any_fp_bnf :: _, ctors = ctors0, dtors = dtors0, |
1121 val (pre_bnfs, (fp_res as {bnfs = fp_bnfs as any_fp_bnf :: _, ctors = ctors0, dtors = dtors0, |
1119 xtor_co_iterss = xtor_co_iterss0, xtor_co_induct, dtor_ctors, ctor_dtors, ctor_injects, |
1122 xtor_co_iterss = xtor_co_iterss0, xtor_co_induct, dtor_ctors, ctor_dtors, ctor_injects, |
1120 dtor_injects, xtor_map_thms, xtor_set_thmss, xtor_rel_thms, xtor_co_iter_thmss, ...}, |
1123 dtor_injects, xtor_map_thms, xtor_set_thmss, xtor_rel_thms, xtor_co_iter_thmss, ...}, |
1121 lthy)) = |
1124 lthy)) = |
1122 fp_bnf (construct_fp mixfixes map_bs rel_bs set_bss) fp_bs (map dest_TFree unsorted_As) |
1125 fp_bnf (construct_fp mixfixes map_bs rel_bs set_bss) fp_bs (map dest_TFree unsorted_As) fp_eqs |
1123 fake_Ts fp_eqs no_defs_lthy0; |
1126 no_defs_lthy0 |
|
1127 handle BAD_DEAD (X, X_backdrop) => |
|
1128 (case X_backdrop of |
|
1129 Type (bad_tc, _) => |
|
1130 let |
|
1131 val qsoty = quote o Syntax.string_of_typ fake_lthy; |
|
1132 val fake_T = qsoty (unfreeze_fp X); |
|
1133 val fake_T_backdrop = qsoty (unfreeze_fp X_backdrop); |
|
1134 fun register_hint () = |
|
1135 "\nUse the " ^ quote (fst (fst @{command_spec "bnf"})) ^ " command to register " ^ |
|
1136 quote bad_tc ^ " as a bounded natural functor to allow nested (co)recursion through \ |
|
1137 \it"; |
|
1138 in |
|
1139 if is_some (bnf_of no_defs_lthy bad_tc) orelse |
|
1140 is_some (fp_sugar_of no_defs_lthy bad_tc) then |
|
1141 error ("Non-strictly-positive " ^ co_prefix fp ^ "recursive occurrence of type " ^ |
|
1142 fake_T ^ " in type expression " ^ fake_T_backdrop) |
|
1143 else if is_some (Datatype_Data.get_info (Proof_Context.theory_of no_defs_lthy) |
|
1144 bad_tc) then |
|
1145 error ("Unsupported " ^ co_prefix fp ^ "recursive occurrence of type " ^ fake_T ^ |
|
1146 " via the old-style datatype " ^ quote bad_tc ^ " in type expression " ^ |
|
1147 fake_T_backdrop ^ register_hint ()) |
|
1148 else |
|
1149 error ("Unsupported " ^ co_prefix fp ^ "recursive occurrence of type " ^ fake_T ^ |
|
1150 " via type constructor " ^ quote bad_tc ^ " in type expression " ^ fake_T_backdrop ^ |
|
1151 register_hint ()) |
|
1152 end); |
1124 |
1153 |
1125 val time = time lthy; |
1154 val time = time lthy; |
1126 val timer = time (Timer.startRealTimer ()); |
1155 val timer = time (Timer.startRealTimer ()); |
1127 |
1156 |
1128 val nesting_bnfs = nesty_bnfs lthy ctrXs_Tsss As; |
1157 val nesting_bnfs = nesty_bnfs lthy ctrXs_Tsss As; |