src/Pure/type_infer.ML
changeset 39295 6e8b0672c6a2
parent 39294 27fae73fe769
child 39296 e275d581a218
equal deleted inserted replaced
39294:27fae73fe769 39295:6e8b0672c6a2
    10   val is_param: indexname -> bool
    10   val is_param: indexname -> bool
    11   val is_paramT: typ -> bool
    11   val is_paramT: typ -> bool
    12   val param: int -> string * sort -> typ
    12   val param: int -> string * sort -> typ
    13   val paramify_vars: typ -> typ
    13   val paramify_vars: typ -> typ
    14   val paramify_dummies: typ -> int -> typ * int
    14   val paramify_dummies: typ -> int -> typ * int
    15   val fixate_params: Name.context -> term list -> term list
    15   val fixate_params: Proof.context -> term list -> term list
    16   val infer_types: Proof.context -> (string -> typ option) -> (indexname -> typ option) ->
    16   val infer_types: Proof.context -> (string -> typ option) -> (indexname -> typ option) ->
    17     term list -> term list
    17     term list -> term list
    18 end;
    18 end;
    19 
    19 
    20 structure Type_Infer: TYPE_INFER =
    20 structure Type_Infer: TYPE_INFER =
    52           let val (Ts', maxidx') = fold_map paramify Ts maxidx
    52           let val (Ts', maxidx') = fold_map paramify Ts maxidx
    53           in (Type (a, Ts'), maxidx') end
    53           in (Type (a, Ts'), maxidx') end
    54       | paramify T maxidx = (T, maxidx);
    54       | paramify T maxidx = (T, maxidx);
    55   in paramify end;
    55   in paramify end;
    56 
    56 
    57 fun fixate_params name_context ts =
    57 fun fixate_params ctxt ts =
    58   let
    58   let
    59     fun subst_param (xi, S) (inst, used) =
    59     fun subst_param (xi, S) (inst, used) =
    60       if is_param xi then
    60       if is_param xi then
    61         let
    61         let
    62           val [a] = Name.invents used Name.aT 1;
    62           val [a] = Name.invents used Name.aT 1;
    63           val used' = Name.declare a used;
    63           val used' = Name.declare a used;
    64         in (((xi, S), TFree (a, S)) :: inst, used') end
    64         in (((xi, S), TFree (a, S)) :: inst, used') end
    65       else (inst, used);
    65       else (inst, used);
    66     val name_context' = (fold o fold_types) Term.declare_typ_names ts name_context;
    66     val used = (fold o fold_types) Term.declare_typ_names ts (Variable.names_of ctxt);
    67     val (inst, _) = fold_rev subst_param (fold Term.add_tvars ts []) ([], name_context');
    67     val (inst, _) = fold_rev subst_param (fold Term.add_tvars ts []) ([], used);
    68   in (map o map_types) (Term_Subst.instantiateT inst) ts end;
    68   in (map o map_types) (Term_Subst.instantiateT inst) ts end;
    69 
    69 
    70 
    70 
    71 
    71 
    72 (** prepare types/terms: create inference parameters **)
    72 (** prepare types/terms: create inference parameters **)
   186     val used =
   186     val used =
   187       (fold o fold_types) (add_names tye) ts (fold (add_names tye) Ts (Variable.names_of ctxt));
   187       (fold o fold_types) (add_names tye) ts (fold (add_names tye) Ts (Variable.names_of ctxt));
   188     val parms = rev ((fold o fold_types) (add_parms tye) ts (fold (add_parms tye) Ts []));
   188     val parms = rev ((fold o fold_types) (add_parms tye) ts (fold (add_parms tye) Ts []));
   189     val names = Name.invents used ("?" ^ Name.aT) (length parms);
   189     val names = Name.invents used ("?" ^ Name.aT) (length parms);
   190     val tab = Vartab.make (parms ~~ names);
   190     val tab = Vartab.make (parms ~~ names);
   191     val idx = Variable.maxidx_of ctxt + 1;
       
   192 
   191 
   193     fun finish_typ T =
   192     fun finish_typ T =
   194       (case deref tye T of
   193       (case deref tye T of
   195         Type (a, Ts) => Type (a, map finish_typ Ts)
   194         Type (a, Ts) => Type (a, map finish_typ Ts)
   196       | U as TFree _ => U
   195       | U as TFree _ => U
   197       | U as TVar (xi, S) =>
   196       | U as TVar (xi, S) =>
   198           (case Vartab.lookup tab xi of
   197           (case Vartab.lookup tab xi of
   199             NONE => U
   198             NONE => U
   200           | SOME a => TVar ((a, idx), S)));
   199           | SOME a => TVar ((a, 0), S)));
   201   in (map finish_typ Ts, map (Type.strip_constraints o Term.map_types finish_typ) ts) end;
   200   in (map finish_typ Ts, map (Type.strip_constraints o Term.map_types finish_typ) ts) end;
   202 
   201 
   203 
   202 
   204 
   203 
   205 (** order-sorted unification of types **)
   204 (** order-sorted unification of types **)