17 xxrecs: term list, |
17 xxrecs: term list, |
18 xxfold_thmss: thm list list, |
18 xxfold_thmss: thm list list, |
19 xxrec_thmss: thm list list}; |
19 xxrec_thmss: thm list list}; |
20 |
20 |
21 val fp_sugar_of: Proof.context -> string -> fp_sugar option |
21 val fp_sugar_of: Proof.context -> string -> fp_sugar option |
|
22 |
|
23 val mk_fp_iter_fun_types: term -> typ list |
|
24 val mk_fun_arg_typess: int -> int list -> typ -> typ list list |
|
25 val unzip_recT: typ list -> typ -> typ list * typ list |
|
26 val mk_fold_fun_typess: typ list list list -> typ list list -> typ list list |
|
27 val mk_rec_fun_typess: typ list -> typ list list list -> typ list list -> typ list list |
22 |
28 |
23 val derive_induct_fold_rec_thms_for_types: BNF_Def.bnf list -> term list -> term list -> thm -> |
29 val derive_induct_fold_rec_thms_for_types: BNF_Def.bnf list -> term list -> term list -> thm -> |
24 thm list -> thm list -> BNF_Def.bnf list -> BNF_Def.bnf list -> typ list -> typ list -> |
30 thm list -> thm list -> BNF_Def.bnf list -> BNF_Def.bnf list -> typ list -> typ list -> |
25 typ list -> term list list -> thm list list -> term list -> term list -> thm list -> thm list -> |
31 typ list -> term list list -> thm list list -> term list -> term list -> thm list -> thm list -> |
26 Proof.context -> |
32 Proof.context -> |
204 val Us0 = distinct (op =) (map (if lfp then body_type else domain_type) f_Us); |
210 val Us0 = distinct (op =) (map (if lfp then body_type else domain_type) f_Us); |
205 in |
211 in |
206 Term.subst_atomic_types (Ts0 @ Us0 ~~ Ts @ Us) t |
212 Term.subst_atomic_types (Ts0 @ Us0 ~~ Ts @ Us) t |
207 end; |
213 end; |
208 |
214 |
|
215 val mk_fp_iter_fun_types = fst o split_last o binder_types o fastype_of; |
|
216 |
209 fun mk_fp_iter lfp As Cs fp_iters0 = |
217 fun mk_fp_iter lfp As Cs fp_iters0 = |
210 map (mk_xxiter lfp As Cs) fp_iters0 |
218 map (mk_xxiter lfp As Cs) fp_iters0 |
211 |> (fn ts => (ts, fst (split_last (binder_types (fastype_of (hd ts)))))); |
219 |> (fn ts => (ts, mk_fp_iter_fun_types (hd ts))); |
212 |
220 |
213 fun massage_rec_fun_arg_typesss fpTs = |
221 fun unzip_recT fpTs T = |
214 let |
222 let |
215 fun project_recT proj = |
223 fun project_recT proj = |
216 let |
224 let |
217 fun project (Type (s as @{type_name prod}, Ts as [T, U])) = |
225 fun project (Type (s as @{type_name prod}, Ts as [T, U])) = |
218 if member (op =) fpTs T then proj (T, U) else Type (s, map project Ts) |
226 if member (op =) fpTs T then proj (T, U) else Type (s, map project Ts) |
219 | project (Type (s, Ts)) = Type (s, map project Ts) |
227 | project (Type (s, Ts)) = Type (s, map project Ts) |
220 | project T = T; |
228 | project T = T; |
221 in project end; |
229 in project end; |
222 fun unzip_recT T = |
|
223 if exists_subtype_in fpTs T then ([project_recT fst T], [project_recT snd T]) else ([T], []); |
|
224 in |
230 in |
225 map (map (flat_rec unzip_recT)) |
231 if exists_subtype_in fpTs T then ([project_recT fst T], [project_recT snd T]) else ([T], []) |
226 end; |
232 end; |
|
233 |
|
234 val massage_rec_fun_arg_typesss = map o map o flat_rec o unzip_recT; |
227 |
235 |
228 val mk_fold_fun_typess = map2 (map2 (curry (op --->))); |
236 val mk_fold_fun_typess = map2 (map2 (curry (op --->))); |
229 val mk_rec_fun_typess = mk_fold_fun_typess oo massage_rec_fun_arg_typesss; |
237 val mk_rec_fun_typess = mk_fold_fun_typess oo massage_rec_fun_arg_typesss; |
230 |
238 |
|
239 fun mk_fun_arg_typess n ms = map2 dest_tupleT ms o dest_sumTN_balanced n o domain_type; |
|
240 |
231 fun mk_fold_rec_terms_types fpTs Css ns mss ctor_fold_fun_Ts ctor_rec_fun_Ts lthy = |
241 fun mk_fold_rec_terms_types fpTs Css ns mss ctor_fold_fun_Ts ctor_rec_fun_Ts lthy = |
232 let |
242 let |
233 fun mk_fun_arg_typess n ms = map2 dest_tupleT ms o dest_sumTN_balanced n o domain_type; |
|
234 |
|
235 val y_Tsss = map3 mk_fun_arg_typess ns mss ctor_fold_fun_Ts; |
243 val y_Tsss = map3 mk_fun_arg_typess ns mss ctor_fold_fun_Ts; |
236 val g_Tss = mk_fold_fun_typess y_Tsss Css; |
244 val g_Tss = mk_fold_fun_typess y_Tsss Css; |
237 |
245 |
238 val ((gss, ysss), lthy) = |
246 val ((gss, ysss), lthy) = |
239 lthy |
247 lthy |