src/HOL/Nominal/nominal_primrec.ML
changeset 33726 0878aecbf119
parent 33671 4b0f2599ed48
child 33766 c679f05600cd
equal deleted inserted replaced
33725:a8481da77270 33726:0878aecbf119
   237   | common_prefix eq (x :: xs, y :: ys) =
   237   | common_prefix eq (x :: xs, y :: ys) =
   238       if eq (x, y) then x :: common_prefix eq (xs, ys) else [];
   238       if eq (x, y) then x :: common_prefix eq (xs, ys) else [];
   239 
   239 
   240 local
   240 local
   241 
   241 
   242 fun gen_primrec set_group prep_spec prep_term invs fctxt raw_fixes raw_params raw_spec lthy =
   242 fun gen_primrec prep_spec prep_term invs fctxt raw_fixes raw_params raw_spec lthy =
   243   let
   243   let
   244     val (fixes', spec) = fst (prep_spec (raw_fixes @ raw_params) raw_spec lthy);
   244     val (fixes', spec) = fst (prep_spec (raw_fixes @ raw_params) raw_spec lthy);
   245     val fixes = List.take (fixes', length raw_fixes);
   245     val fixes = List.take (fixes', length raw_fixes);
   246     val (names_atts, spec') = split_list spec;
   246     val (names_atts, spec') = split_list spec;
   247     val eqns' = map unquantify spec'
   247     val eqns' = map unquantify spec'
   278     val names2 = map fst eqns;
   278     val names2 = map fst eqns;
   279     val _ = if eq_set (op =) (names1, names2) then ()
   279     val _ = if eq_set (op =) (names1, names2) then ()
   280       else primrec_err ("functions " ^ commas_quote names2 ^
   280       else primrec_err ("functions " ^ commas_quote names2 ^
   281         "\nare not mutually recursive");
   281         "\nare not mutually recursive");
   282     val (defs_thms, lthy') = lthy |>
   282     val (defs_thms, lthy') = lthy |>
   283       set_group ? Local_Theory.set_group (serial ()) |>
       
   284       fold_map (apfst (snd o snd) oo Local_Theory.define Thm.definitionK o fst) defs';
   283       fold_map (apfst (snd o snd) oo Local_Theory.define Thm.definitionK o fst) defs';
   285     val qualify = Binding.qualify false
   284     val qualify = Binding.qualify false
   286       (space_implode "_" (map (Long_Name.base_name o #1) defs));
   285       (space_implode "_" (map (Long_Name.base_name o #1) defs));
   287     val names_atts' = map (apfst qualify) names_atts;
   286     val names_atts' = map (apfst qualify) names_atts;
   288     val cert = cterm_of (ProofContext.theory_of lthy');
   287     val cert = cterm_of (ProofContext.theory_of lthy');
   382     Seq.hd
   381     Seq.hd
   383   end;
   382   end;
   384 
   383 
   385 in
   384 in
   386 
   385 
   387 val add_primrec = gen_primrec false Specification.check_spec (K I);
   386 val add_primrec = gen_primrec Specification.check_spec (K I);
   388 val add_primrec_cmd = gen_primrec true Specification.read_spec Syntax.read_term;
   387 val add_primrec_cmd = gen_primrec Specification.read_spec Syntax.read_term;
   389 
   388 
   390 end;
   389 end;
   391 
   390 
   392 
   391 
   393 (* outer syntax *)
   392 (* outer syntax *)