src/HOL/thy_syntax.ML
changeset 8657 b9475dad85ed
parent 8623 5668aaf41c36
child 8813 abc0f3722aed
equal deleted inserted replaced
8656:1062572b5b37 8657:b9475dad85ed
   191 
   191 
   192 
   192 
   193 
   193 
   194 (** primrec **)
   194 (** primrec **)
   195 
   195 
       
   196 fun mk_patterns eqns = mk_list (map (fn (s, _) => if s = "" then "_" else s) eqns);
       
   197 fun mk_eqns eqns = mk_list (map (fn (x, y) => mk_pair (mk_pair (quote x, y), "[]")) eqns);
       
   198 
   196 fun mk_primrec_decl (alt_name, eqns) =
   199 fun mk_primrec_decl (alt_name, eqns) =
   197   let
   200   ";\nval (thy, " ^ mk_patterns eqns ^ ") = PrimrecPackage.add_primrec " ^ alt_name ^ " "
   198     val names = map (fn (s, _) => if s = "" then "_" else s) eqns
   201   ^ mk_eqns eqns ^ " " ^ " thy;\n\
   199   in
   202   \val thy = thy\n"
   200     ";\nval (thy, " ^ mk_list names ^ ") = PrimrecPackage.add_primrec " ^ alt_name ^ " " ^
       
   201     mk_list (map (fn (x, y) => mk_pair (mk_pair (quote x, y), "[]")) eqns) ^
       
   202     " " ^ " thy;\n\
       
   203     \val thy = thy\n"
       
   204   end;
       
   205 
   203 
   206 (* either names and axioms or just axioms *)
   204 (* either names and axioms or just axioms *)
   207 val primrec_decl = (optional ("(" $$-- name --$$ ")") "\"\"" --
   205 val primrec_decl = optional ("(" $$-- name --$$ ")") "\"\"" --
   208   (repeat1 ((ident -- string) || (string >> pair "")))) >> mk_primrec_decl;
   206   repeat1 (ident -- string || (string >> pair "")) >> mk_primrec_decl;
   209 
   207 
   210 
   208 
   211 (*** recdef: interface to Slind's TFL ***)
   209 (*** recdef: interface to Slind's TFL ***)
   212 
   210 
   213 (** TFL with explicit WF relations **)
   211 (** TFL with explicit WF relations **)
   214 
   212 
   215 (*fname: name of function being defined; rel: well-founded relation*)
   213 (*fname: name of function being defined; rel: well-founded relation*)
   216 fun mk_recdef_decl ((((fname, rel), congs), ss), axms) =
   214 fun mk_recdef_decl ((((fname, rel), congs), ss), eqns) =
   217   let
   215   let
   218     val fid = unenclose fname;
   216     val fid = unenclose fname;
   219     val congs_text = mk_list (map (fn c => mk_pair (c, "[]")) congs);
   217     val congs_text = mk_list (map (fn c => mk_pair (c, "[]")) congs);
   220     val axms_text = mk_big_list axms;
       
   221   in
   218   in
   222     ";\n\n\
   219     ";\n\n\
   223     \local\n\
   220     \local\n\
   224     \fun simpset() = Simplifier.simpset_of thy;\n\
   221     \fun simpset() = Simplifier.simpset_of thy;\n\
   225     \val (thy, result) = thy |> RecdefPackage.add_recdef " ^ quote fid ^ " " ^ rel ^ "\n" ^
   222     \val (thy, result) = thy |> RecdefPackage.add_recdef " ^ quote fid ^ " " ^ rel ^ "\n" ^
   226     axms_text ^ "\n(Some (" ^ ss ^ "))\n" ^ congs_text ^ ";\n\
   223     mk_eqns eqns ^ "\n(Some (" ^ ss ^ "))\n" ^ congs_text ^ ";\n\
   227     \in\n\
   224     \in\n\
   228     \structure " ^ fid ^ " =\n\
   225     \structure " ^ fid ^ " =\n\
   229     \struct\n\
   226     \struct\n\
   230     \  val {simps, induct, tcs} = result;\n\
   227     \  val {simps, rules = " ^ mk_patterns eqns ^ ", induct, tcs} = result;\n\
   231     \end;\n\
   228     \end;\n\
   232     \val thy = thy;\n\
   229     \val thy = thy;\n\
   233     \end;\n\
   230     \end;\n\
   234     \val thy = thy\n"
   231     \val thy = thy\n"
   235   end;
   232   end;
   236 
   233 
   237 val recdef_decl =
   234 val recdef_decl =
   238   (name -- string --
   235   name -- string --
   239     optional ("congs" $$-- list1 name) [] --
   236     optional ("congs" $$-- list1 name) [] --
   240     optional ("simpset" $$-- string >> unenclose) "simpset()" --
   237     optional ("simpset" $$-- string >> unenclose) "simpset()" --
   241     repeat1 string >> mk_recdef_decl);
   238     repeat1 (ident -- string || (string >> pair "")) >> mk_recdef_decl;
   242 
   239 
   243 
   240 
   244 (** TFL with no WF relation supplied **)
   241 (** TFL with no WF relation supplied **)
   245 
   242 
   246 (*fname: name of function being defined; rel: well-founded relation*)
   243 (*fname: name of function being defined; rel: well-founded relation*)