src/ZF/Tools/primrec_package.ML
changeset 69593 3dda49e08b9d
parent 67522 9e712280cc37
child 70474 235396695401
equal deleted inserted replaced
69592:a80d8ec6c998 69593:3dda49e08b9d
   113     fun add_case ((cname, recursor_pair), cases) =
   113     fun add_case ((cname, recursor_pair), cases) =
   114       let val (rhs, recursor_rhs, eq) =
   114       let val (rhs, recursor_rhs, eq) =
   115             case AList.lookup (op =) eqns cname of
   115             case AList.lookup (op =) eqns cname of
   116                 NONE => (warning ("no equation for constructor " ^ cname ^
   116                 NONE => (warning ("no equation for constructor " ^ cname ^
   117                                   "\nin definition of function " ^ fname);
   117                                   "\nin definition of function " ^ fname);
   118                          (Const (@{const_name zero}, Ind_Syntax.iT),
   118                          (Const (\<^const_name>\<open>zero\<close>, Ind_Syntax.iT),
   119                           #2 recursor_pair, Const (@{const_name zero}, Ind_Syntax.iT)))
   119                           #2 recursor_pair, Const (\<^const_name>\<open>zero\<close>, Ind_Syntax.iT)))
   120               | SOME (rhs, cargs', eq) =>
   120               | SOME (rhs, cargs', eq) =>
   121                     (rhs, inst_recursor (recursor_pair, cargs'), eq)
   121                     (rhs, inst_recursor (recursor_pair, cargs'), eq)
   122           val allowed_terms = map use_fabs (#2 (strip_comb recursor_rhs))
   122           val allowed_terms = map use_fabs (#2 (strip_comb recursor_rhs))
   123           val abs = List.foldr absterm rhs allowed_terms
   123           val abs = List.foldr absterm rhs allowed_terms
   124       in
   124       in
   195 
   195 
   196 
   196 
   197 (* outer syntax *)
   197 (* outer syntax *)
   198 
   198 
   199 val _ =
   199 val _ =
   200   Outer_Syntax.command @{command_keyword primrec} "define primitive recursive functions on datatypes"
   200   Outer_Syntax.command \<^command_keyword>\<open>primrec\<close> "define primitive recursive functions on datatypes"
   201     (Scan.repeat1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)
   201     (Scan.repeat1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)
   202       >> (Toplevel.theory o (#1 oo (primrec o map (fn ((x, y), z) => ((x, z), y))))));
   202       >> (Toplevel.theory o (#1 oo (primrec o map (fn ((x, y), z) => ((x, z), y))))));
   203 
   203 
   204 end;
   204 end;
   205 
   205