192 (list_comb (Const (rec_name, dummyT), |
192 (list_comb (Const (rec_name, dummyT), |
193 fs @ map Bound (0 :: (length ls downto 1)))) |
193 fs @ map Bound (0 :: (length ls downto 1)))) |
194 val def_name = Thm.def_name (Sign.base_name fname); |
194 val def_name = Thm.def_name (Sign.base_name fname); |
195 val rhs = singleton (Syntax.check_terms ctxt) raw_rhs; |
195 val rhs = singleton (Syntax.check_terms ctxt) raw_rhs; |
196 val SOME var = get_first (fn ((b, _), mx) => |
196 val SOME var = get_first (fn ((b, _), mx) => |
197 if Binding.base_name b = fname then SOME (b, mx) else NONE) fixes; |
197 if Binding.name_of b = fname then SOME (b, mx) else NONE) fixes; |
198 in (var, ((Binding.name def_name, []), rhs)) end; |
198 in (var, ((Binding.name def_name, []), rhs)) end; |
199 |
199 |
200 |
200 |
201 (* find datatypes which contain all datatypes in tnames' *) |
201 (* find datatypes which contain all datatypes in tnames' *) |
202 |
202 |
229 |
229 |
230 fun gen_primrec set_group prep_spec raw_fixes raw_spec lthy = |
230 fun gen_primrec set_group prep_spec raw_fixes raw_spec lthy = |
231 let |
231 let |
232 val (fixes, spec) = prepare_spec prep_spec lthy raw_fixes raw_spec; |
232 val (fixes, spec) = prepare_spec prep_spec lthy raw_fixes raw_spec; |
233 val eqns = fold_rev (process_eqn (fn v => Variable.is_fixed lthy v |
233 val eqns = fold_rev (process_eqn (fn v => Variable.is_fixed lthy v |
234 orelse exists (fn ((w, _), _) => v = Binding.base_name w) fixes) o snd) spec []; |
234 orelse exists (fn ((w, _), _) => v = Binding.name_of w) fixes) o snd) spec []; |
235 val tnames = distinct (op =) (map (#1 o snd) eqns); |
235 val tnames = distinct (op =) (map (#1 o snd) eqns); |
236 val dts = find_dts (DatatypePackage.get_datatypes (ProofContext.theory_of lthy)) tnames tnames; |
236 val dts = find_dts (DatatypePackage.get_datatypes (ProofContext.theory_of lthy)) tnames tnames; |
237 val main_fns = map (fn (tname, {index, ...}) => |
237 val main_fns = map (fn (tname, {index, ...}) => |
238 (index, (fst o the o find_first (fn (_, x) => #1 x = tname)) eqns)) dts; |
238 (index, (fst o the o find_first (fn (_, x) => #1 x = tname)) eqns)) dts; |
239 val {descr, rec_names, rec_rewrites, ...} = |
239 val {descr, rec_names, rec_rewrites, ...} = |
246 val names2 = map fst eqns; |
246 val names2 = map fst eqns; |
247 val _ = if gen_eq_set (op =) (names1, names2) then () |
247 val _ = if gen_eq_set (op =) (names1, names2) then () |
248 else primrec_error ("functions " ^ commas_quote names2 ^ |
248 else primrec_error ("functions " ^ commas_quote names2 ^ |
249 "\nare not mutually recursive"); |
249 "\nare not mutually recursive"); |
250 val prefix = space_implode "_" (map (Sign.base_name o #1) defs); |
250 val prefix = space_implode "_" (map (Sign.base_name o #1) defs); |
251 val qualify = Binding.qualify prefix; |
251 val qualify = Binding.qualify false prefix; |
252 val spec' = (map o apfst) |
252 val spec' = (map o apfst) |
253 (fn (b, attrs) => (qualify b, Code.add_default_eqn_attrib :: attrs)) spec; |
253 (fn (b, attrs) => (qualify b, Code.add_default_eqn_attrib :: attrs)) spec; |
254 val simp_atts = map (Attrib.internal o K) |
254 val simp_atts = map (Attrib.internal o K) |
255 [Simplifier.simp_add, Nitpick_Const_Simp_Thms.add]; |
255 [Simplifier.simp_add, Nitpick_Const_Simp_Thms.add]; |
256 in |
256 in |
297 Scan.optional (P.$$$ "(" |-- P.!!! |
297 Scan.optional (P.$$$ "(" |-- P.!!! |
298 (((P.$$$ "unchecked" >> K true) -- Scan.optional P.name "" || |
298 (((P.$$$ "unchecked" >> K true) -- Scan.optional P.name "" || |
299 P.name >> pair false) --| P.$$$ ")")) (false, ""); |
299 P.name >> pair false) --| P.$$$ ")")) (false, ""); |
300 |
300 |
301 val old_primrec_decl = |
301 val old_primrec_decl = |
302 opt_unchecked_name -- Scan.repeat1 ((SpecParse.opt_thm_name ":" >> apfst Binding.base_name) -- P.prop); |
302 opt_unchecked_name -- Scan.repeat1 ((SpecParse.opt_thm_name ":" >> apfst Binding.name_of) -- P.prop); |
303 |
303 |
304 fun pipe_error t = P.!!! (Scan.fail_with (K |
304 fun pipe_error t = P.!!! (Scan.fail_with (K |
305 (cat_lines ["Equations must be separated by " ^ quote "|", quote t]))); |
305 (cat_lines ["Equations must be separated by " ^ quote "|", quote t]))); |
306 |
306 |
307 val statement = SpecParse.opt_thm_name ":" -- P.prop --| Scan.ahead |
307 val statement = SpecParse.opt_thm_name ":" -- P.prop --| Scan.ahead |