src/Pure/type_infer.ML
changeset 39288 f1ae2493d93f
parent 39287 d30be6791038
child 39289 92b50c8bb67b
equal deleted inserted replaced
39287:d30be6791038 39288:f1ae2493d93f
     6 
     6 
     7 signature TYPE_INFER =
     7 signature TYPE_INFER =
     8 sig
     8 sig
     9   val anyT: sort -> typ
     9   val anyT: sort -> typ
    10   val polymorphicT: typ -> typ
    10   val polymorphicT: typ -> typ
    11   val constrain: typ -> term -> term
       
    12   val is_param: indexname -> bool
    11   val is_param: indexname -> bool
    13   val param: int -> string * sort -> typ
    12   val param: int -> string * sort -> typ
    14   val paramify_vars: typ -> typ
    13   val paramify_vars: typ -> typ
    15   val paramify_dummies: typ -> int -> typ * int
    14   val paramify_dummies: typ -> int -> typ * int
    16   val fixate_params: Name.context -> term list -> term list
    15   val fixate_params: Name.context -> term list -> term list
    28 
    27 
    29 fun anyT S = TFree ("'_dummy_", S);
    28 fun anyT S = TFree ("'_dummy_", S);
    30 
    29 
    31 (*indicate polymorphic Vars*)
    30 (*indicate polymorphic Vars*)
    32 fun polymorphicT T = Type ("_polymorphic_", [T]);
    31 fun polymorphicT T = Type ("_polymorphic_", [T]);
    33 
       
    34 val constrain = Syntax.type_constraint;
       
    35 
    32 
    36 
    33 
    37 (* type inference parameters -- may get instantiated *)
    34 (* type inference parameters -- may get instantiated *)
    38 
    35 
    39 fun is_param (x, _: int) = String.isPrefix "?" x;
    36 fun is_param (x, _: int) = String.isPrefix "?" x;
   416 fun infer_types pp tsig check_typs const_type var_type used maxidx raw_ts =
   413 fun infer_types pp tsig check_typs const_type var_type used maxidx raw_ts =
   417   let
   414   let
   418     (*constrain vars*)
   415     (*constrain vars*)
   419     val get_type = the_default dummyT o var_type;
   416     val get_type = the_default dummyT o var_type;
   420     val constrain_vars = Term.map_aterms
   417     val constrain_vars = Term.map_aterms
   421       (fn Free (x, T) => constrain T (Free (x, get_type (x, ~1)))
   418       (fn Free (x, T) => Type.constraint T (Free (x, get_type (x, ~1)))
   422         | Var (xi, T) => constrain T (Var (xi, get_type xi))
   419         | Var (xi, T) => Type.constraint T (Var (xi, get_type xi))
   423         | t => t);
   420         | t => t);
   424 
   421 
   425     (*convert to preterms*)
   422     (*convert to preterms*)
   426     val ts = burrow_types check_typs raw_ts;
   423     val ts = burrow_types check_typs raw_ts;
   427     val (ts', (_, _, idx)) =
   424     val (ts', (_, _, idx)) =