src/Pure/Isar/proof_context.ML
changeset 15574 b1d1b5bfc464
parent 15570 8d8c70b41bab
child 15596 8665d08085df
equal deleted inserted replaced
15573:cf53c2dcf440 15574:b1d1b5bfc464
   695     | (used, _) => used));
   695     | (used, _) => used));
   696 
   696 
   697 val ins_occs = foldl_term_types (fn t => foldl_atyps
   697 val ins_occs = foldl_term_types (fn t => foldl_atyps
   698   (fn (tab, TFree (x, _)) => Symtab.update_multi ((x, t), tab) | (tab, _) => tab));
   698   (fn (tab, TFree (x, _)) => Symtab.update_multi ((x, t), tab) | (tab, _) => tab));
   699 
   699 
   700 fun ins_skolem def_ty = Library.foldr
   700 fun ins_skolem def_ty = foldr
   701   (fn ((x, x'), types) =>
   701   (fn ((x, x'), types) =>
   702     (case def_ty x' of
   702     (case def_ty x' of
   703       SOME T => Vartab.update (((x, ~1), T), types)
   703       SOME T => Vartab.update (((x, ~1), T), types)
   704     | NONE => types));
   704     | NONE => types));
   705 
   705 
   714 
   714 
   715 fun declare_occ (ctxt as Context {asms = (_, fixes), ...}, t) =
   715 fun declare_occ (ctxt as Context {asms = (_, fixes), ...}, t) =
   716   declare_syn (ctxt, t)
   716   declare_syn (ctxt, t)
   717   |> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs (occ, t)))
   717   |> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs (occ, t)))
   718   |> map_defaults (fn (types, sorts, used, occ) =>
   718   |> map_defaults (fn (types, sorts, used, occ) =>
   719       (ins_skolem (fn x => Vartab.lookup (types, (x, ~1))) (fixes, types), sorts, used, occ));
   719       (ins_skolem (fn x => Vartab.lookup (types, (x, ~1))) types fixes, sorts, used, occ));
   720 
   720 
   721 in
   721 in
   722 
   722 
   723 fun declare_term t ctxt = declare_occ (ctxt, t);
   723 fun declare_term t ctxt = declare_occ (ctxt, t);
   724 fun declare_terms ts ctxt = Library.foldl declare_occ (ctxt, ts);
   724 fun declare_terms ts ctxt = Library.foldl declare_occ (ctxt, ts);
   771       then gen else a :: gen;
   771       then gen else a :: gen;
   772   in fn tfrees => Library.foldl add ([], tfrees) end;
   772   in fn tfrees => Library.foldl add ([], tfrees) end;
   773 
   773 
   774 fun generalize inner outer ts =
   774 fun generalize inner outer ts =
   775   let
   775   let
   776     val tfrees = generalize_tfrees inner outer (Library.foldr Term.add_term_tfree_names (ts, []));
   776     val tfrees = generalize_tfrees inner outer (foldr Term.add_term_tfree_names [] ts);
   777     fun gen (x, S) = if x mem_string tfrees then TVar ((x, 0), S) else TFree (x, S);
   777     fun gen (x, S) = if x mem_string tfrees then TVar ((x, 0), S) else TFree (x, S);
   778   in map (Term.map_term_types (Term.map_type_tfree gen)) ts end;
   778   in map (Term.map_term_types (Term.map_type_tfree gen)) ts end;
   779 
   779 
   780 
   780 
   781 
   781 
  1265   let
  1265   let
  1266     fun replace (opt_x :: xs) ((y, T) :: ys) = (getOpt (opt_x,y), T) :: replace xs ys
  1266     fun replace (opt_x :: xs) ((y, T) :: ys) = (getOpt (opt_x,y), T) :: replace xs ys
  1267       | replace [] ys = ys
  1267       | replace [] ys = ys
  1268       | replace (_ :: _) [] = raise CONTEXT ("Too many parameters for case " ^ quote name, ctxt);
  1268       | replace (_ :: _) [] = raise CONTEXT ("Too many parameters for case " ^ quote name, ctxt);
  1269   in
  1269   in
  1270     if null (Library.foldr Term.add_typ_tvars (map snd fixes, [])) andalso
  1270     if null (foldr Term.add_typ_tvars [] (map snd fixes)) andalso
  1271       null (Library.foldr Term.add_term_vars (List.concat (map snd assumes), [])) then
  1271       null (foldr Term.add_term_vars [] (List.concat (map snd assumes))) then
  1272         {fixes = replace xs fixes, assumes = assumes, binds = map drop_schematic binds}
  1272         {fixes = replace xs fixes, assumes = assumes, binds = map drop_schematic binds}
  1273     else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt)
  1273     else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt)
  1274   end;
  1274   end;
  1275 
  1275 
  1276 fun get_case (ctxt as Context {cases, ...}) name xs =
  1276 fun get_case (ctxt as Context {cases, ...}) name xs =