src/Tools/subtyping.ML
changeset 43591 d4cbd6feffdf
parent 43278 1fbdcebb364b
child 44338 700008399ee5
equal deleted inserted replaced
43590:0940a64beca2 43591:d4cbd6feffdf
    82 val is_stypeT = fn (Type (_, [])) => true | _ => false;
    82 val is_stypeT = fn (Type (_, [])) => true | _ => false;
    83 val is_compT = fn (Type (_, _ :: _)) => true | _ => false;
    83 val is_compT = fn (Type (_, _ :: _)) => true | _ => false;
    84 val is_freeT = fn (TFree _) => true | _ => false;
    84 val is_freeT = fn (TFree _) => true | _ => false;
    85 val is_fixedvarT = fn (TVar (xi, _)) => not (Type_Infer.is_param xi) | _ => false;
    85 val is_fixedvarT = fn (TVar (xi, _)) => not (Type_Infer.is_param xi) | _ => false;
    86 val is_funtype = fn (Type ("fun", [_, _])) => true | _ => false;
    86 val is_funtype = fn (Type ("fun", [_, _])) => true | _ => false;
       
    87 val is_identity = fn (Abs (_, _, Bound 0)) => true | _ => false;
    87 
    88 
    88 
    89 
    89 (* unification *)
    90 (* unification *)
    90 
    91 
    91 exception TYPE_INFERENCE_ERROR of unit -> string;
    92 exception TYPE_INFERENCE_ERROR of unit -> string;
   612               NONE => raise Fail ("No map function for " ^ a ^ " known")
   613               NONE => raise Fail ("No map function for " ^ a ^ " known")
   613             | SOME tmap =>
   614             | SOME tmap =>
   614                 let
   615                 let
   615                   val used_coes = map_filter sub_co ((snd tmap) ~~ (Ts ~~ Us));
   616                   val used_coes = map_filter sub_co ((snd tmap) ~~ (Ts ~~ Us));
   616                 in
   617                 in
   617                   Term.list_comb
   618                   if null (filter (not o is_identity) used_coes)
       
   619                   then Abs (Name.uu, Type (a, Ts), Bound 0)
       
   620                   else Term.list_comb
   618                     (inst (fst tmap) (ts_of (map fastype_of used_coes)), used_coes)
   621                     (inst (fst tmap) (ts_of (map fastype_of used_coes)), used_coes)
   619                 end)
   622                 end)
   620           end
   623           end
   621   | (T, U) =>
   624   | (T, U) =>
   622         if Type.could_unify (T, U)
   625         if Type.could_unify (T, U)