7 *) |
7 *) |
8 |
8 |
9 signature BNF_FP_REC_SUGAR_UTIL = |
9 signature BNF_FP_REC_SUGAR_UTIL = |
10 sig |
10 sig |
11 datatype rec_call = |
11 datatype rec_call = |
12 No_Rec of int | |
12 No_Rec of int * typ | |
13 Mutual_Rec of int (*before*) * int (*after*) | |
13 Mutual_Rec of (int * typ) (*before*) * (int * typ) (*after*) | |
14 Nested_Rec of int |
14 Nested_Rec of int * typ |
15 |
15 |
16 datatype corec_call = |
16 datatype corec_call = |
17 Dummy_No_Corec of int | |
17 Dummy_No_Corec of int | |
18 No_Corec of int | |
18 No_Corec of int | |
19 Mutual_Corec of int (*stop?*) * int (*end*) * int (*continue*) | |
19 Mutual_Corec of int (*stop?*) * int (*end*) * int (*continue*) | |
97 open BNF_FP_Util |
97 open BNF_FP_Util |
98 open BNF_FP_Def_Sugar |
98 open BNF_FP_Def_Sugar |
99 open BNF_FP_N2M_Sugar |
99 open BNF_FP_N2M_Sugar |
100 |
100 |
101 datatype rec_call = |
101 datatype rec_call = |
102 No_Rec of int | |
102 No_Rec of int * typ | |
103 Mutual_Rec of int * int | |
103 Mutual_Rec of (int * typ) * (int * typ) | |
104 Nested_Rec of int; |
104 Nested_Rec of int * typ; |
105 |
105 |
106 datatype corec_call = |
106 datatype corec_call = |
107 Dummy_No_Corec of int | |
107 Dummy_No_Corec of int | |
108 No_Corec of int | |
108 No_Corec of int | |
109 Mutual_Corec of int * int * int | |
109 Mutual_Corec of int * int * int | |
565 val Cs_rho = map (fst o dest_TVar) Cs ~~ pad_list HOLogic.unitT nn res_Ts; |
565 val Cs_rho = map (fst o dest_TVar) Cs ~~ pad_list HOLogic.unitT nn res_Ts; |
566 |
566 |
567 val substA = Term.subst_TVars As_rho; |
567 val substA = Term.subst_TVars As_rho; |
568 val substAT = Term.typ_subst_TVars As_rho; |
568 val substAT = Term.typ_subst_TVars As_rho; |
569 val substCT = Term.typ_subst_TVars Cs_rho; |
569 val substCT = Term.typ_subst_TVars Cs_rho; |
|
570 val substACT = substAT o substCT; |
570 |
571 |
571 val perm_Cs' = map substCT perm_Cs; |
572 val perm_Cs' = map substCT perm_Cs; |
572 |
573 |
573 fun offset_of_ctr 0 _ = 0 |
574 fun offset_of_ctr 0 _ = 0 |
574 | offset_of_ctr n (({ctrs, ...} : ctr_sugar) :: ctr_sugars) = |
575 | offset_of_ctr n (({ctrs, ...} : ctr_sugar) :: ctr_sugars) = |
575 length ctrs + offset_of_ctr (n - 1) ctr_sugars; |
576 length ctrs + offset_of_ctr (n - 1) ctr_sugars; |
576 |
577 |
577 fun call_of [i] [T] = (if exists_subtype_in Cs T then Nested_Rec else No_Rec) i |
578 fun call_of [i] [T] = (if exists_subtype_in Cs T then Nested_Rec else No_Rec) (i, substACT T) |
578 | call_of [i, i'] _ = Mutual_Rec (i, i'); |
579 | call_of [i, i'] [T, T'] = Mutual_Rec ((i, substACT T), (i', substACT T')); |
579 |
580 |
580 fun mk_ctr_spec ctr offset fun_arg_Tss rec_thm = |
581 fun mk_ctr_spec ctr offset fun_arg_Tss rec_thm = |
581 let |
582 let |
582 val (fun_arg_hss, _) = indexedd fun_arg_Tss 0; |
583 val (fun_arg_hss, _) = indexedd fun_arg_Tss 0; |
583 val fun_arg_hs = flat_rec_arg_args fun_arg_hss; |
584 val fun_arg_hs = flat_rec_arg_args fun_arg_hss; |