788 (#axioms (AxClass.get_info thy class) handle ERROR _ => [])) |
788 (#axioms (AxClass.get_info thy class) handle ERROR _ => [])) |
789 superclasses |
789 superclasses |
790 (* replace the (at most one) schematic type variable in each axiom *) |
790 (* replace the (at most one) schematic type variable in each axiom *) |
791 (* by the actual type 'T' *) |
791 (* by the actual type 'T' *) |
792 val monomorphic_class_axioms = map (fn (axname, ax) => |
792 val monomorphic_class_axioms = map (fn (axname, ax) => |
793 (case Term.term_tvars ax of |
793 (case Term.add_tvars ax [] of |
794 [] => |
794 [] => |
795 (axname, ax) |
795 (axname, ax) |
796 | [(idx, S)] => |
796 | [(idx, S)] => |
797 (axname, monomorphic_term (Vartab.make [(idx, (S, T))]) ax) |
797 (axname, monomorphic_term (Vartab.make [(idx, (S, T))]) ax) |
798 | _ => |
798 | _ => |
940 (* return function types, set types, non-recursive IDTs, or *) |
940 (* return function types, set types, non-recursive IDTs, or *) |
941 (* 'propT'. For IDTs, also the argument types of constructors *) |
941 (* 'propT'. For IDTs, also the argument types of constructors *) |
942 (* and all mutually recursive IDTs are considered. *) |
942 (* and all mutually recursive IDTs are considered. *) |
943 (* ------------------------------------------------------------------------- *) |
943 (* ------------------------------------------------------------------------- *) |
944 |
944 |
945 (* theory -> Term.term -> Term.typ list *) |
|
946 |
|
947 fun ground_types thy t = |
945 fun ground_types thy t = |
948 let |
946 let |
949 (* Term.typ * Term.typ list -> Term.typ list *) |
947 fun collect_types T acc = |
950 fun collect_types (T, acc) = |
|
951 (case T of |
948 (case T of |
952 Type ("fun", [T1, T2]) => collect_types (T1, collect_types (T2, acc)) |
949 Type ("fun", [T1, T2]) => collect_types T1 (collect_types T2 acc) |
953 | Type ("prop", []) => acc |
950 | Type ("prop", []) => acc |
954 | Type ("set", [T1]) => collect_types (T1, acc) |
951 | Type ("set", [T1]) => collect_types T1 acc |
955 | Type (s, Ts) => |
952 | Type (s, Ts) => |
956 (case DatatypePackage.get_datatype thy s of |
953 (case DatatypePackage.get_datatype thy s of |
957 SOME info => (* inductive datatype *) |
954 SOME info => (* inductive datatype *) |
958 let |
955 let |
959 val index = #index info |
956 val index = #index info |
974 let |
971 let |
975 val dT = typ_of_dtyp descr typ_assoc d |
972 val dT = typ_of_dtyp descr typ_assoc d |
976 in |
973 in |
977 case d of |
974 case d of |
978 DatatypeAux.DtTFree _ => |
975 DatatypeAux.DtTFree _ => |
979 collect_types (dT, acc) |
976 collect_types dT acc |
980 | DatatypeAux.DtType (_, ds) => |
977 | DatatypeAux.DtType (_, ds) => |
981 collect_types (dT, foldr collect_dtyp acc ds) |
978 collect_types dT (foldr collect_dtyp acc ds) |
982 | DatatypeAux.DtRec i => |
979 | DatatypeAux.DtRec i => |
983 if dT mem acc then |
980 if dT mem acc then |
984 acc (* prevent infinite recursion *) |
981 acc (* prevent infinite recursion *) |
985 else |
982 else |
986 let |
983 let |
1006 collect_dtyp (DatatypeAux.DtRec index, acc) |
1003 collect_dtyp (DatatypeAux.DtRec index, acc) |
1007 end |
1004 end |
1008 | NONE => |
1005 | NONE => |
1009 (* not an inductive datatype, e.g. defined via "typedef" or *) |
1006 (* not an inductive datatype, e.g. defined via "typedef" or *) |
1010 (* "typedecl" *) |
1007 (* "typedecl" *) |
1011 insert (op =) T (foldr collect_types acc Ts)) |
1008 insert (op =) T (fold collect_types Ts acc)) |
1012 | TFree _ => insert (op =) T acc |
1009 | TFree _ => insert (op =) T acc |
1013 | TVar _ => insert (op =) T acc) |
1010 | TVar _ => insert (op =) T acc) |
1014 in |
1011 in |
1015 it_term_types collect_types (t, []) |
1012 fold_types collect_types t [] |
1016 end; |
1013 end; |
1017 |
1014 |
1018 (* ------------------------------------------------------------------------- *) |
1015 (* ------------------------------------------------------------------------- *) |
1019 (* string_of_typ: (rather naive) conversion from types to strings, used to *) |
1016 (* string_of_typ: (rather naive) conversion from types to strings, used to *) |
1020 (* look up the size of a type in 'sizes'. Parameterized *) |
1017 (* look up the size of a type in 'sizes'. Parameterized *) |
1285 let |
1282 let |
1286 (* disallow schematic type variables, since we cannot properly negate *) |
1283 (* disallow schematic type variables, since we cannot properly negate *) |
1287 (* terms containing them (their logical meaning is that there EXISTS a *) |
1284 (* terms containing them (their logical meaning is that there EXISTS a *) |
1288 (* type s.t. ...; to refute such a formula, we would have to show that *) |
1285 (* type s.t. ...; to refute such a formula, we would have to show that *) |
1289 (* for ALL types, not ...) *) |
1286 (* for ALL types, not ...) *) |
1290 val _ = null (term_tvars t) orelse |
1287 val _ = null (Term.add_tvars t []) orelse |
1291 error "Term to be refuted contains schematic type variables" |
1288 error "Term to be refuted contains schematic type variables" |
1292 |
1289 |
1293 (* existential closure over schematic variables *) |
1290 (* existential closure over schematic variables *) |
1294 (* (Term.indexname * Term.typ) list *) |
1291 (* (Term.indexname * Term.typ) list *) |
1295 val vars = sort_wrt (fst o fst) (map dest_Var (OldTerm.term_vars t)) |
1292 val vars = sort_wrt (fst o fst) (map dest_Var (OldTerm.term_vars t)) |