461 fun bad_inst ((x, S), T) = |
461 fun bad_inst ((x, S), T) = |
462 if Sign.of_sort sign (T, S) then NONE else SOME x |
462 if Sign.of_sort sign (T, S) then NONE else SOME x |
463 val bads = List.mapPartial bad_inst (args ~~ types); |
463 val bads = List.mapPartial bad_inst (args ~~ types); |
464 |
464 |
465 val inst = map fst args ~~ types; |
465 val inst = map fst args ~~ types; |
466 val subst = Term.map_type_tfree (fn (x, _) => valOf (assoc (inst, x))); |
466 val subst = Term.map_type_tfree (the o AList.lookup (op =) inst o fst); |
467 val parent' = Option.map (apfst (map subst)) parent; |
467 val parent' = Option.map (apfst (map subst)) parent; |
468 val fields' = map (apsnd subst) fields; |
468 val fields' = map (apsnd subst) fields; |
469 val extension' = apsnd (map subst) extension; |
469 val extension' = apsnd (map subst) extension; |
470 in |
470 in |
471 conditional (not (null bads)) (fn () => |
471 conditional (not (null bads)) (fn () => |
549 else raise TERM (msg ^ "expecting field " ^ field ^ " but got " ^ name, [t]) |
549 else raise TERM (msg ^ "expecting field " ^ field ^ " but got " ^ name, [t]) |
550 | splitargs [] (fargs as (_::_)) = ([],fargs) |
550 | splitargs [] (fargs as (_::_)) = ([],fargs) |
551 | splitargs (_::_) [] = raise TERM (msg ^ "expecting more fields", [t]) |
551 | splitargs (_::_) [] = raise TERM (msg ^ "expecting more fields", [t]) |
552 | splitargs _ _ = ([],[]); |
552 | splitargs _ _ = ([],[]); |
553 |
553 |
554 fun get_sort xs n = (case assoc (xs,n) of |
554 fun get_sort xs n = AList.lookup (op =) xs n |> the_default (Sign.defaultS sg); |
555 SOME s => s |
|
556 | NONE => Sign.defaultS sg); |
|
557 |
|
558 |
555 |
559 fun to_type t = Sign.certify_typ sg |
556 fun to_type t = Sign.certify_typ sg |
560 (Sign.intern_typ sg |
557 (Sign.intern_typ sg |
561 (Syntax.typ_of_term (get_sort (Syntax.raw_term_sorts t)) I t)); |
558 (Syntax.typ_of_term (get_sort (Syntax.raw_term_sorts t)) I t)); |
562 |
559 |
690 fun record_type_abbr_tr' default_tr' abbr alphas zeta lastExt schemeT sg tm = |
687 fun record_type_abbr_tr' default_tr' abbr alphas zeta lastExt schemeT sg tm = |
691 let |
688 let |
692 (* tm is term representation of a (nested) field type. We first reconstruct the *) |
689 (* tm is term representation of a (nested) field type. We first reconstruct the *) |
693 (* type from tm so that we can continue on the type level rather then the term level.*) |
690 (* type from tm so that we can continue on the type level rather then the term level.*) |
694 |
691 |
695 fun get_sort xs n = (case assoc (xs,n) of |
692 fun get_sort xs n = AList.lookup (op =) xs n |> the_default (Sign.defaultS sg); |
696 SOME s => s |
|
697 | NONE => Sign.defaultS sg); |
|
698 |
693 |
699 (* WORKAROUND: |
694 (* WORKAROUND: |
700 * If a record type occurs in an error message of type inference there |
695 * If a record type occurs in an error message of type inference there |
701 * may be some internal frees donoted by ??: |
696 * may be some internal frees donoted by ??: |
702 * (Const "_tfree",_)$Free ("??'a",_). |
697 * (Const "_tfree",_)$Free ("??'a",_). |
737 else default_tr' sg tm |
732 else default_tr' sg tm |
738 end |
733 end |
739 |
734 |
740 fun record_type_tr' sep mark record record_scheme sg t = |
735 fun record_type_tr' sep mark record record_scheme sg t = |
741 let |
736 let |
742 fun get_sort xs n = (case assoc (xs,n) of |
737 fun get_sort xs n = AList.lookup (op =) xs n |> the_default (Sign.defaultS sg); |
743 SOME s => s |
|
744 | NONE => Sign.defaultS sg); |
|
745 |
738 |
746 val T = Sign.intern_typ sg (Syntax.typ_of_term (get_sort (Syntax.raw_term_sorts t)) I t) |
739 val T = Sign.intern_typ sg (Syntax.typ_of_term (get_sort (Syntax.raw_term_sorts t)) I t) |
747 |
740 |
748 fun term_of_type T = Syntax.term_of_typ (!Syntax.show_sorts) (Sign.extern_typ sg T); |
741 fun term_of_type T = Syntax.term_of_typ (!Syntax.show_sorts) (Sign.extern_typ sg T); |
749 |
742 |
1212 Type (name, Ts) => (Ts, name) |
1205 Type (name, Ts) => (Ts, name) |
1213 | _ => error ("Bad parent record specification: " ^ quote s)); |
1206 | _ => error ("Bad parent record specification: " ^ quote s)); |
1214 |
1207 |
1215 fun read_typ sign (env, s) = |
1208 fun read_typ sign (env, s) = |
1216 let |
1209 let |
1217 fun def_sort (x, ~1) = assoc (env, x) |
1210 fun def_sort (x, ~1) = AList.lookup (op =) env x |
1218 | def_sort _ = NONE; |
1211 | def_sort _ = NONE; |
1219 val T = Type.no_tvars (Sign.read_typ (sign, def_sort) s) handle TYPE (msg, _, _) => error msg; |
1212 val T = Type.no_tvars (Sign.read_typ (sign, def_sort) s) handle TYPE (msg, _, _) => error msg; |
1220 in (Term.add_typ_tfrees (T, env), T) end; |
1213 in (Term.add_typ_tfrees (T, env), T) end; |
1221 |
1214 |
1222 fun cert_typ sign (env, raw_T) = |
1215 fun cert_typ sign (env, raw_T) = |
1252 val (x, ca) = (case rev (Library.drop (length params, ys)) of |
1245 val (x, ca) = (case rev (Library.drop (length params, ys)) of |
1253 [] => (head_of (fst (HOLogic.dest_eq (HOLogic.dest_Trueprop |
1246 [] => (head_of (fst (HOLogic.dest_eq (HOLogic.dest_Trueprop |
1254 (hd (rev (Logic.strip_assums_hyp (hd (prems_of rule')))))))), true) |
1247 (hd (rev (Logic.strip_assums_hyp (hd (prems_of rule')))))))), true) |
1255 | [x] => (head_of x, false)); |
1248 | [x] => (head_of x, false)); |
1256 val rule'' = cterm_instantiate (map (pairself cert) (case (rev params) of |
1249 val rule'' = cterm_instantiate (map (pairself cert) (case (rev params) of |
1257 [] => (case assoc (map dest_Free (term_frees (prop_of st)), s) of |
1250 [] => (case AList.lookup (op =) (map dest_Free (term_frees (prop_of st))) s of |
1258 NONE => sys_error "try_param_tac: no such variable" |
1251 NONE => sys_error "try_param_tac: no such variable" |
1259 | SOME T => [(P, if ca then concl else lambda (Free (s, T)) concl), |
1252 | SOME T => [(P, if ca then concl else lambda (Free (s, T)) concl), |
1260 (x, Free (s, T))]) |
1253 (x, Free (s, T))]) |
1261 | (_, T) :: _ => [(P, list_abs (params, if ca then concl |
1254 | (_, T) :: _ => [(P, list_abs (params, if ca then concl |
1262 else incr_boundvars 1 (Abs (s, T, concl)))), |
1255 else incr_boundvars 1 (Abs (s, T, concl)))), |