106 kpart is the number of this mutually recursive part*) |
106 kpart is the number of this mutually recursive part*) |
107 fun mk_con_defs (kpart, con_ty_list) = |
107 fun mk_con_defs (kpart, con_ty_list) = |
108 let val ncon = length con_ty_list (*number of constructors*) |
108 let val ncon = length con_ty_list (*number of constructors*) |
109 fun mk_def (((id,T,syn), name, args, prems), kcon) = |
109 fun mk_def (((id,T,syn), name, args, prems), kcon) = |
110 (*kcon is index of constructor*) |
110 (*kcon is index of constructor*) |
111 Primitive_Defs.mk_defpair (list_comb (Const (full_name name, T), args), |
111 OldGoals.mk_defpair (list_comb (Const (full_name name, T), args), |
112 mk_inject npart kpart |
112 mk_inject npart kpart |
113 (mk_inject ncon kcon (mk_tuple args))) |
113 (mk_inject ncon kcon (mk_tuple args))) |
114 in ListPair.map mk_def (con_ty_list, 1 upto ncon) end; |
114 in ListPair.map mk_def (con_ty_list, 1 upto ncon) end; |
115 |
115 |
116 |
116 |
155 val case_args = maps (map #1) case_lists; |
155 val case_args = maps (map #1) case_lists; |
156 |
156 |
157 val case_const = Const (case_name, case_typ); |
157 val case_const = Const (case_name, case_typ); |
158 val case_tm = list_comb (case_const, case_args); |
158 val case_tm = list_comb (case_const, case_args); |
159 |
159 |
160 val case_def = Primitive_Defs.mk_defpair |
160 val case_def = OldGoals.mk_defpair |
161 (case_tm, Balanced_Tree.make (fn (t1, t2) => Su.elim $ t1 $ t2) (map call_case case_lists)); |
161 (case_tm, Balanced_Tree.make (fn (t1, t2) => Su.elim $ t1 $ t2) (map call_case case_lists)); |
162 |
162 |
163 |
163 |
164 (** Generating function variables for the recursor definition |
164 (** Generating function variables for the recursor definition |
165 Non-identifiers (e.g. infixes) get a name of the form f_op_nnn. **) |
165 Non-identifiers (e.g. infixes) get a name of the form f_op_nnn. **) |
230 list_comb (Const (recursor_name, recursor_typ), recursor_args); |
230 list_comb (Const (recursor_name, recursor_typ), recursor_args); |
231 |
231 |
232 val recursor_cases = map call_recursor (flat case_lists ~~ flat recursor_lists); |
232 val recursor_cases = map call_recursor (flat case_lists ~~ flat recursor_lists); |
233 |
233 |
234 val recursor_def = |
234 val recursor_def = |
235 Primitive_Defs.mk_defpair |
235 OldGoals.mk_defpair |
236 (recursor_tm, |
236 (recursor_tm, |
237 @{const Univ.Vrecursor} $ |
237 @{const Univ.Vrecursor} $ |
238 absfree ("rec", @{typ i}, list_comb (case_const, recursor_cases))); |
238 absfree ("rec", @{typ i}, list_comb (case_const, recursor_cases))); |
239 |
239 |
240 (* Build the new theory *) |
240 (* Build the new theory *) |