src/HOL/BNF/Tools/bnf_fp_rec_sugar.ML
changeset 53310 8af01463b2d3
parent 53304 cfef783090eb
child 53329 c31c0c311cf0
equal deleted inserted replaced
53309:42a99f732a40 53310:8af01463b2d3
     7 
     7 
     8 signature BNF_FP_REC_SUGAR =
     8 signature BNF_FP_REC_SUGAR =
     9 sig
     9 sig
    10   val add_primrec_cmd: (binding * string option * mixfix) list ->
    10   val add_primrec_cmd: (binding * string option * mixfix) list ->
    11     (Attrib.binding * string) list -> local_theory -> local_theory;
    11     (Attrib.binding * string) list -> local_theory -> local_theory;
       
    12   val add_primcorec_cmd: bool ->
       
    13     (binding * string option * mixfix) list * (Attrib.binding * string) list -> Proof.context ->
       
    14     Proof.state
    12 end;
    15 end;
    13 
    16 
    14 (* TODO:
    17 (* TODO:
    15      - error handling for indirect calls
    18      - error handling for indirect calls
    16 *)
    19 *)
    31 
    34 
    32 fun finds eq = fold_map (fn x => List.partition (curry eq x) #>> pair x);
    35 fun finds eq = fold_map (fn x => List.partition (curry eq x) #>> pair x);
    33 
    36 
    34 val simp_attrs = @{attributes [simp]};
    37 val simp_attrs = @{attributes [simp]};
    35 
    38 
       
    39 
       
    40 
       
    41 (* Primrec *)
    36 
    42 
    37 type eqn_data = {
    43 type eqn_data = {
    38   fun_name: string,
    44   fun_name: string,
    39   rec_type: typ,
    45   rec_type: typ,
    40   ctr: term,
    46   ctr: term,
   388     then error ("primrec_new error:\n  " ^ str)
   394     then error ("primrec_new error:\n  " ^ str)
   389     else error ("primrec_new error:\n  " ^ str ^ "\nin\n  " ^
   395     else error ("primrec_new error:\n  " ^ str ^ "\nin\n  " ^
   390       space_implode "\n  " (map (quote o Syntax.string_of_term lthy) eqns))
   396       space_implode "\n  " (map (quote o Syntax.string_of_term lthy) eqns))
   391 
   397 
   392 
   398 
   393 val _ = Outer_Syntax.local_theory
   399 
   394   @{command_spec "primrec_new"}
   400 (* Primcorec *)
   395   "define primitive recursive functions"
       
   396   (Parse.fixes -- Parse_Spec.where_alt_specs >> uncurry add_primrec_cmd);
       
   397 
       
   398 
       
   399 
       
   400 
       
   401 
       
   402 
       
   403 
       
   404 
       
   405 
       
   406 
       
   407 
       
   408 
       
   409 
       
   410 
       
   411 
       
   412 
   401 
   413 type co_eqn_data_dtr_disc = {
   402 type co_eqn_data_dtr_disc = {
   414   fun_name: string,
   403   fun_name: string,
   415   ctr_no: int,
   404   ctr_no: int,
   416   cond: term,
   405   cond: term,
   732     if null eqns
   721     if null eqns
   733     then error ("primcorec error:\n  " ^ str)
   722     then error ("primcorec error:\n  " ^ str)
   734     else error ("primcorec error:\n  " ^ str ^ "\nin\n  " ^
   723     else error ("primcorec error:\n  " ^ str ^ "\nin\n  " ^
   735       space_implode "\n  " (map (quote o Syntax.string_of_term lthy) eqns))
   724       space_implode "\n  " (map (quote o Syntax.string_of_term lthy) eqns))
   736 
   725 
   737 val _ = Outer_Syntax.local_theory_to_proof
       
   738   @{command_spec "primcorec"}
       
   739   "define primitive corecursive functions"
       
   740   (Parse.opt_keyword "sequential" -- (Parse.fixes -- Parse_Spec.where_alt_specs) >>
       
   741     uncurry add_primcorec_cmd);
       
   742 
       
   743 end;
   726 end;