src/Pure/type_infer.ML
changeset 18339 64cb06a0bb50
parent 17496 26535df536ae
child 18939 18e2a2676d80
equal deleted inserted replaced
18338:ed2d0e60fbcc 18339:64cb06a0bb50
     7 
     7 
     8 signature TYPE_INFER =
     8 signature TYPE_INFER =
     9 sig
     9 sig
    10   val anyT: sort -> typ
    10   val anyT: sort -> typ
    11   val logicT: typ
    11   val logicT: typ
       
    12   val mixfixT: Syntax.mixfix -> typ
    12   val polymorphicT: typ -> typ
    13   val polymorphicT: typ -> typ
    13   val appl_error: Pretty.pp -> string -> term -> typ -> term -> typ -> string list
    14   val appl_error: Pretty.pp -> string -> term -> typ -> term -> typ -> string list
    14   val constrain: term -> typ -> term
    15   val constrain: term -> typ -> term
    15   val param: int -> string * sort -> typ
    16   val param: int -> string * sort -> typ
    16   val paramify_dummies: int * typ -> int * typ
    17   val paramify_dummies: typ -> int -> typ * int
    17   val get_sort: Type.tsig -> (indexname -> sort option) -> (sort -> sort)
    18   val get_sort: Type.tsig -> (indexname -> sort option) -> (sort -> sort)
    18     -> (indexname * sort) list -> indexname -> sort
    19     -> (indexname * sort) list -> indexname -> sort
    19   val infer_types: Pretty.pp
    20   val infer_types: Pretty.pp
    20     -> Type.tsig -> (string -> typ option) -> (indexname -> typ option)
    21     -> Type.tsig -> (string -> typ option) -> (indexname -> typ option)
    21     -> (indexname -> sort option) -> (string -> string) -> (typ -> typ)
    22     -> (indexname -> sort option) -> (string -> string) -> (typ -> typ)
   102 
   103 
   103 (* pretyp(s)_of *)
   104 (* pretyp(s)_of *)
   104 
   105 
   105 fun anyT S = TFree ("'_dummy_", S);
   106 fun anyT S = TFree ("'_dummy_", S);
   106 val logicT = anyT [];
   107 val logicT = anyT [];
       
   108 
       
   109 fun mixfixT (Binder _) = (logicT --> logicT) --> logicT
       
   110   | mixfixT mx = replicate (Syntax.mixfix_args mx) logicT ---> logicT;
       
   111 
   107 
   112 
   108 (*indicate polymorphic Vars*)
   113 (*indicate polymorphic Vars*)
   109 fun polymorphicT T = Type ("_polymorphic_", [T]);
   114 fun polymorphicT T = Type ("_polymorphic_", [T]);
   110 
   115 
   111 fun pretyp_of is_param (params, typ) =
   116 fun pretyp_of is_param (params, typ) =
   434 (* user parameters *)
   439 (* user parameters *)
   435 
   440 
   436 fun is_param (x, _) = size x > 0 andalso ord x = ord "?";
   441 fun is_param (x, _) = size x > 0 andalso ord x = ord "?";
   437 fun param i (x, S) = TVar (("?" ^ x, i), S);
   442 fun param i (x, S) = TVar (("?" ^ x, i), S);
   438 
   443 
   439 fun paramify_dummies (maxidx, TFree ("'_dummy_", S)) =
   444 val paramify_dummies =
   440       (maxidx + 1, param (maxidx + 1) ("'dummy", S))
   445   let
   441   | paramify_dummies (maxidx, Type (a, Ts)) =
   446     fun dummy S maxidx = (param (maxidx + 1) ("'dummy", S), maxidx + 1);
   442       let val (maxidx', Ts') = foldl_map paramify_dummies (maxidx, Ts)
   447 
   443       in (maxidx', Type (a, Ts')) end
   448     fun paramify (TFree ("'_dummy_", S)) maxidx = dummy S maxidx
   444   | paramify_dummies arg = arg;
   449       | paramify (Type ("dummy", _)) maxidx = dummy [] maxidx
       
   450       | paramify (Type (a, Ts)) maxidx =
       
   451           let val (Ts', maxidx') = fold_map paramify Ts maxidx
       
   452           in (Type (a, Ts'), maxidx') end
       
   453       | paramify T maxidx = (T, maxidx);
       
   454   in paramify end;
   445 
   455 
   446 
   456 
   447 (* decode sort constraints *)
   457 (* decode sort constraints *)
   448 
   458 
   449 fun get_sort tsig def_sort map_sort raw_env =
   459 fun get_sort tsig def_sort map_sort raw_env =