src/Pure/type.ML
changeset 56050 fdccbb97915a
parent 56025 d74fed45fa8b
child 56056 4d46d53566e6
equal deleted inserted replaced
56044:f78b4c3e8e84 56050:fdccbb97915a
    74   val devar: tyenv -> typ -> typ
    74   val devar: tyenv -> typ -> typ
    75   val typ_match: tsig -> typ * typ -> tyenv -> tyenv
    75   val typ_match: tsig -> typ * typ -> tyenv -> tyenv
    76   val typ_instance: tsig -> typ * typ -> bool
    76   val typ_instance: tsig -> typ * typ -> bool
    77   val raw_match: typ * typ -> tyenv -> tyenv
    77   val raw_match: typ * typ -> tyenv -> tyenv
    78   val raw_matches: typ list * typ list -> tyenv -> tyenv
    78   val raw_matches: typ list * typ list -> tyenv -> tyenv
       
    79   val could_match: typ * typ -> bool
       
    80   val could_matches: typ list * typ list -> bool
    79   val raw_instance: typ * typ -> bool
    81   val raw_instance: typ * typ -> bool
    80   exception TUNIFY
    82   exception TUNIFY
    81   val unify: tsig -> typ * typ -> tyenv * int -> tyenv * int
    83   val unify: tsig -> typ * typ -> tyenv * int -> tyenv * int
    82   val raw_unify: typ * typ -> tyenv -> tyenv
    84   val raw_unify: typ * typ -> tyenv -> tyenv
    83   val raw_unifys: typ list * typ list -> tyenv -> tyenv
    85   val raw_unifys: typ list * typ list -> tyenv -> tyenv
   459   | raw_match _ _ = raise TYPE_MATCH
   461   | raw_match _ _ = raise TYPE_MATCH
   460 and raw_matches (T :: Ts, U :: Us) subs = raw_matches (Ts, Us) (raw_match (T, U) subs)
   462 and raw_matches (T :: Ts, U :: Us) subs = raw_matches (Ts, Us) (raw_match (T, U) subs)
   461   | raw_matches ([], []) subs = subs
   463   | raw_matches ([], []) subs = subs
   462   | raw_matches _ _ = raise TYPE_MATCH;
   464   | raw_matches _ _ = raise TYPE_MATCH;
   463 
   465 
       
   466 (*fast matching filter*)
       
   467 fun could_match (Type (a, Ts), Type (b, Us)) = a = b andalso could_matches (Ts, Us)
       
   468   | could_match (TFree (a, _), TFree (b, _)) = a = b
       
   469   | could_match (TVar _, _) = true
       
   470   | could_match _ = false
       
   471 and could_matches (T :: Ts, U :: Us) = could_match (T, U) andalso could_matches (Ts, Us)
       
   472   | could_matches ([], []) = true
       
   473   | could_matches _ = false;
       
   474 
   464 fun raw_instance (T, U) =
   475 fun raw_instance (T, U) =
   465   (raw_match (U, T) Vartab.empty; true) handle TYPE_MATCH => false;
   476   if could_match (U, T) then
       
   477     (raw_match (U, T) Vartab.empty; true) handle TYPE_MATCH => false
       
   478   else false;
   466 
   479 
   467 
   480 
   468 (* unification *)
   481 (* unification *)
   469 
   482 
   470 exception TUNIFY;
   483 exception TUNIFY;