11 (Attrib.binding * string) list -> local_theory -> local_theory; |
11 (Attrib.binding * string) list -> local_theory -> local_theory; |
12 val add_primcorec_cmd: bool -> |
12 val add_primcorec_cmd: bool -> |
13 (binding * string option * mixfix) list * (Attrib.binding * string) list -> Proof.context -> |
13 (binding * string option * mixfix) list * (Attrib.binding * string) list -> Proof.context -> |
14 Proof.state |
14 Proof.state |
15 end; |
15 end; |
16 |
|
17 (* TODO: |
|
18 - error handling for indirect calls |
|
19 *) |
|
20 |
16 |
21 structure BNF_FP_Rec_Sugar : BNF_FP_REC_SUGAR = |
17 structure BNF_FP_Rec_Sugar : BNF_FP_REC_SUGAR = |
22 struct |
18 struct |
23 |
19 |
24 open BNF_Util |
20 open BNF_Util |
339 primrec_error_eqn ("argument " ^ quote (Syntax.string_of_term lthy' ctr) ^ |
335 primrec_error_eqn ("argument " ^ quote (Syntax.string_of_term lthy' ctr) ^ |
340 " is not a constructor in left-hand side") user_eqn) eqns_data end; |
336 " is not a constructor in left-hand side") user_eqn) eqns_data end; |
341 |
337 |
342 val defs = build_defs lthy' bs funs_data rec_specs get_indices; |
338 val defs = build_defs lthy' bs funs_data rec_specs get_indices; |
343 |
339 |
344 fun prove def_thms' {ctr_specs, nested_map_id's, nested_map_comps, ...} induct_thm fun_data |
340 fun prove def_thms' {ctr_specs, nested_map_idents, nested_map_comps, ...} induct_thm fun_data |
345 lthy = |
341 lthy = |
346 let |
342 let |
347 val fun_name = #fun_name (hd fun_data); |
343 val fun_name = #fun_name (hd fun_data); |
348 val def_thms = map (snd o snd) def_thms'; |
344 val def_thms = map (snd o snd) def_thms'; |
349 val simp_thms = finds (fn (x, y) => #ctr x = #ctr y) fun_data ctr_specs |
345 val simp_thms = finds (fn (x, y) => #ctr x = #ctr y) fun_data ctr_specs |
350 |> fst |
346 |> fst |
351 |> map_filter (try (fn (x, [y]) => |
347 |> map_filter (try (fn (x, [y]) => |
352 (#user_eqn x, length (#left_args x) + length (#right_args x), #rec_thm y))) |
348 (#user_eqn x, length (#left_args x) + length (#right_args x), #rec_thm y))) |
353 |> map (fn (user_eqn, num_extra_args, rec_thm) => |
349 |> map (fn (user_eqn, num_extra_args, rec_thm) => |
354 mk_primrec_tac lthy num_extra_args nested_map_id's nested_map_comps def_thms rec_thm |
350 mk_primrec_tac lthy num_extra_args nested_map_idents nested_map_comps def_thms rec_thm |
355 |> K |> Goal.prove lthy [] [] user_eqn) |
351 |> K |> Goal.prove lthy [] [] user_eqn) |
356 |
352 |
357 val notes = |
353 val notes = |
358 [(inductN, if actual_nn > 1 then [induct_thm] else [], []), |
354 [(inductN, if actual_nn > 1 then [induct_thm] else [], []), |
359 (simpsN, simp_thms, simp_attrs)] |
355 (simpsN, simp_thms, simp_attrs)] |