363 |
363 |
364 |
364 |
365 |
365 |
366 (** default sorts and types **) |
366 (** default sorts and types **) |
367 |
367 |
368 val def_sort = Vartab.curried_lookup o #2 o defaults_of; |
368 val def_sort = Vartab.lookup o #2 o defaults_of; |
369 |
369 |
370 fun def_type ctxt pattern xi = |
370 fun def_type ctxt pattern xi = |
371 let val {binds, defs = (types, _, _, _), ...} = rep_context ctxt in |
371 let val {binds, defs = (types, _, _, _), ...} = rep_context ctxt in |
372 (case Vartab.curried_lookup types xi of |
372 (case Vartab.lookup types xi of |
373 NONE => |
373 NONE => |
374 if pattern then NONE |
374 if pattern then NONE |
375 else Vartab.curried_lookup binds xi |> Option.map (TypeInfer.polymorphicT o #2) |
375 else Vartab.lookup binds xi |> Option.map (TypeInfer.polymorphicT o #2) |
376 | some => some) |
376 | some => some) |
377 end; |
377 end; |
378 |
378 |
379 fun default_type ctxt x = Vartab.curried_lookup (#1 (defaults_of ctxt)) (x, ~1); |
379 fun default_type ctxt x = Vartab.lookup (#1 (defaults_of ctxt)) (x, ~1); |
380 val used_types = #3 o defaults_of; |
380 val used_types = #3 o defaults_of; |
381 |
381 |
382 |
382 |
383 |
383 |
384 (** prepare types **) |
384 (** prepare types **) |
491 (*raised when norm has no effect on a term, to do sharing instead of copying*) |
491 (*raised when norm has no effect on a term, to do sharing instead of copying*) |
492 exception SAME; |
492 exception SAME; |
493 |
493 |
494 val binds = binds_of ctxt; |
494 val binds = binds_of ctxt; |
495 fun norm (t as Var (xi, T)) = |
495 fun norm (t as Var (xi, T)) = |
496 (case Vartab.curried_lookup binds xi of |
496 (case Vartab.lookup binds xi of |
497 SOME (u, U) => |
497 SOME (u, U) => |
498 let |
498 let |
499 val env = unifyT ctxt (T, U) handle Type.TUNIFY => |
499 val env = unifyT ctxt (T, U) handle Type.TUNIFY => |
500 raise TYPE ("norm_term: ill-typed variable assignment", [T, U], [t, u]); |
500 raise TYPE ("norm_term: ill-typed variable assignment", [T, U], [t, u]); |
501 val u' = Envir.subst_TVars env u; |
501 val u' = Envir.subst_TVars env u; |
595 (* declare terms *) |
595 (* declare terms *) |
596 |
596 |
597 local |
597 local |
598 |
598 |
599 val ins_types = fold_aterms |
599 val ins_types = fold_aterms |
600 (fn Free (x, T) => Vartab.curried_update ((x, ~1), T) |
600 (fn Free (x, T) => Vartab.update ((x, ~1), T) |
601 | Var v => Vartab.curried_update v |
601 | Var v => Vartab.update v |
602 | _ => I); |
602 | _ => I); |
603 |
603 |
604 val ins_sorts = fold_types (fold_atyps |
604 val ins_sorts = fold_types (fold_atyps |
605 (fn TFree (x, S) => Vartab.curried_update ((x, ~1), S) |
605 (fn TFree (x, S) => Vartab.update ((x, ~1), S) |
606 | TVar v => Vartab.curried_update v |
606 | TVar v => Vartab.update v |
607 | _ => I)); |
607 | _ => I)); |
608 |
608 |
609 val ins_used = fold_term_types (fn t => |
609 val ins_used = fold_term_types (fn t => |
610 fold_atyps (fn TFree (x, _) => insert (op =) x | _ => I)); |
610 fold_atyps (fn TFree (x, _) => insert (op =) x | _ => I)); |
611 |
611 |
612 val ins_occs = fold_term_types (fn t => |
612 val ins_occs = fold_term_types (fn t => |
613 fold_atyps (fn TFree (x, _) => Symtab.curried_update_multi (x, t) | _ => I)); |
613 fold_atyps (fn TFree (x, _) => Symtab.update_multi (x, t) | _ => I)); |
614 |
614 |
615 fun ins_skolem def_ty = fold_rev (fn (x, x') => |
615 fun ins_skolem def_ty = fold_rev (fn (x, x') => |
616 (case def_ty x' of |
616 (case def_ty x' of |
617 SOME T => Vartab.curried_update ((x, ~1), T) |
617 SOME T => Vartab.update ((x, ~1), T) |
618 | NONE => I)); |
618 | NONE => I)); |
619 |
619 |
620 fun map_defaults f = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
620 fun map_defaults f = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
621 (syntax, asms, binds, thms, cases, f defs)); |
621 (syntax, asms, binds, thms, cases, f defs)); |
622 |
622 |
631 fun declare_term t ctxt = |
631 fun declare_term t ctxt = |
632 ctxt |
632 ctxt |
633 |> declare_term_syntax t |
633 |> declare_term_syntax t |
634 |> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs t occ)) |
634 |> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs t occ)) |
635 |> map_defaults (fn (types, sorts, used, occ) => |
635 |> map_defaults (fn (types, sorts, used, occ) => |
636 (ins_skolem (fn x => Vartab.curried_lookup types (x, ~1)) (fixes_of ctxt) types, |
636 (ins_skolem (fn x => Vartab.lookup types (x, ~1)) (fixes_of ctxt) types, |
637 sorts, used, occ)); |
637 sorts, used, occ)); |
638 |
638 |
639 end; |
639 end; |
640 |
640 |
641 |
641 |
689 | still_fixed _ = false; |
689 | still_fixed _ = false; |
690 val occs_inner = type_occs_of inner; |
690 val occs_inner = type_occs_of inner; |
691 val occs_outer = type_occs_of outer; |
691 val occs_outer = type_occs_of outer; |
692 fun add a gen = |
692 fun add a gen = |
693 if Symtab.defined occs_outer a orelse |
693 if Symtab.defined occs_outer a orelse |
694 exists still_fixed (Symtab.curried_lookup_multi occs_inner a) |
694 exists still_fixed (Symtab.lookup_multi occs_inner a) |
695 then gen else a :: gen; |
695 then gen else a :: gen; |
696 in fn tfrees => fold add tfrees [] end; |
696 in fn tfrees => fold add tfrees [] end; |
697 |
697 |
698 fun generalize inner outer ts = |
698 fun generalize inner outer ts = |
699 let |
699 let |
772 val t' = |
772 val t' = |
773 if null (Term.term_tvars t \\ Term.typ_tvars T) then t |
773 if null (Term.term_tvars t \\ Term.typ_tvars T) then t |
774 else Var ((x ^ "_has_extra_type_vars_on_rhs", i), T); |
774 else Var ((x ^ "_has_extra_type_vars_on_rhs", i), T); |
775 in |
775 in |
776 map_context (fn (syntax, asms, binds, thms, cases, defs) => |
776 map_context (fn (syntax, asms, binds, thms, cases, defs) => |
777 (syntax, asms, Vartab.curried_update ((x, i), (t', T)) binds, thms, cases, defs)) |
777 (syntax, asms, Vartab.update ((x, i), (t', T)) binds, thms, cases, defs)) |
778 o declare_term t' |
778 o declare_term t' |
779 end; |
779 end; |
780 |
780 |
781 fun del_upd_bind (xi, NONE) = del_bind xi |
781 fun del_upd_bind (xi, NONE) = del_bind xi |
782 | del_upd_bind (xi, SOME t) = upd_bind (xi, t); |
782 | del_upd_bind (xi, SOME t) = upd_bind (xi, t); |
930 let |
930 let |
931 val thy = Theory.deref thy_ref; |
931 val thy = Theory.deref thy_ref; |
932 val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref; |
932 val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref; |
933 val name = PureThy.name_of_thmref thmref; |
933 val name = PureThy.name_of_thmref thmref; |
934 in |
934 in |
935 (case Symtab.curried_lookup tab name of |
935 (case Symtab.lookup tab name of |
936 SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths) |
936 SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths) |
937 | NONE => from_thy thy xthmref) |> pick name |
937 | NONE => from_thy thy xthmref) |> pick name |
938 end |
938 end |
939 end; |
939 end; |
940 |
940 |
991 | put_thms (bname, SOME ths) ctxt = ctxt |> map_context |
991 | put_thms (bname, SOME ths) ctxt = ctxt |> map_context |
992 (fn (syntax, asms, binds, (naming, (space, tab), index), cases, defs) => |
992 (fn (syntax, asms, binds, (naming, (space, tab), index), cases, defs) => |
993 let |
993 let |
994 val name = NameSpace.full naming bname; |
994 val name = NameSpace.full naming bname; |
995 val space' = NameSpace.declare naming name space; |
995 val space' = NameSpace.declare naming name space; |
996 val tab' = Symtab.curried_update (name, ths) tab; |
996 val tab' = Symtab.update (name, ths) tab; |
997 val index' = FactIndex.add (is_known ctxt) (name, ths) index; |
997 val index' = FactIndex.add (is_known ctxt) (name, ths) index; |
998 in (syntax, asms, binds, (naming, (space', tab'), index'), cases, defs) end); |
998 in (syntax, asms, binds, (naming, (space', tab'), index'), cases, defs) end); |
999 |
999 |
1000 |
1000 |
1001 (* note_thmss *) |
1001 (* note_thmss *) |