62 |
62 |
63 (*type inference*) |
63 (*type inference*) |
64 val get_sort: type_sig -> (indexname -> sort option) -> (sort -> sort) |
64 val get_sort: type_sig -> (indexname -> sort option) -> (sort -> sort) |
65 -> (indexname * sort) list -> indexname -> sort |
65 -> (indexname * sort) list -> indexname -> sort |
66 val constrain: term -> typ -> term |
66 val constrain: term -> typ -> term |
|
67 val param: string list -> string * sort -> typ |
67 val infer_types: (term -> Pretty.T) -> (typ -> Pretty.T) |
68 val infer_types: (term -> Pretty.T) -> (typ -> Pretty.T) |
68 -> type_sig -> (string -> typ option) -> (indexname -> typ option) |
69 -> type_sig -> (string -> typ option) -> (indexname -> typ option) |
69 -> (indexname -> sort option) -> (string -> string) -> (typ -> typ) |
70 -> (indexname -> sort option) -> (string -> string) -> (typ -> typ) |
70 -> (sort -> sort) -> string list -> bool -> typ list -> term list |
71 -> (sort -> sort) -> string list -> bool -> typ list -> term list |
71 -> term list * (indexname * typ) list |
72 -> term list * (indexname * typ) list |
815 fun constrain t T = |
816 fun constrain t T = |
816 if T = dummyT then t |
817 if T = dummyT then t |
817 else Const ("_type_constraint_", T) $ t; |
818 else Const ("_type_constraint_", T) $ t; |
818 |
819 |
819 |
820 |
|
821 (* user parameters *) |
|
822 |
|
823 fun is_param (x, _) = size x > 0 andalso ord x = ord "?"; |
|
824 fun param used (x, S) = TVar (("?" ^ variant used x, 0), S); |
|
825 |
|
826 |
820 (* decode_types *) |
827 (* decode_types *) |
821 |
828 |
822 (*transform parse tree into raw term*) |
829 (*transform parse tree into raw term*) |
823 fun decode_types tsig is_const def_type def_sort map_const map_type map_sort tm = |
830 fun decode_types tsig is_const def_type def_sort map_const map_type map_sort tm = |
824 let |
831 let |
864 def_sort: partial map from indexnames to sorts (constrains TFrees, TVars) |
871 def_sort: partial map from indexnames to sorts (constrains TFrees, TVars) |
865 used: list of already used type variables |
872 used: list of already used type variables |
866 freeze: if true then generated parameters are turned into TFrees, else TVars |
873 freeze: if true then generated parameters are turned into TFrees, else TVars |
867 *) |
874 *) |
868 |
875 |
869 (*user-supplied inference parameters: ??x.i *) |
|
870 fun q_is_param (x, _) = |
|
871 (case explode x of |
|
872 "?" :: _ => true |
|
873 | _ => false); |
|
874 |
|
875 fun infer_types prt prT tsig const_type def_type def_sort |
876 fun infer_types prt prT tsig const_type def_type def_sort |
876 map_const map_type map_sort used freeze pat_Ts raw_ts = |
877 map_const map_type map_sort used freeze pat_Ts raw_ts = |
877 let |
878 let |
878 val TySg {classrel, arities, ...} = tsig; |
879 val TySg {classrel, arities, ...} = tsig; |
879 val pat_Ts' = map (cert_typ tsig) pat_Ts; |
880 val pat_Ts' = map (cert_typ tsig) pat_Ts; |
880 val is_const = is_some o const_type; |
881 val is_const = is_some o const_type; |
881 val raw_ts' = |
882 val raw_ts' = |
882 map (decode_types tsig is_const def_type def_sort map_const map_type map_sort) raw_ts; |
883 map (decode_types tsig is_const def_type def_sort map_const map_type map_sort) raw_ts; |
883 val (ts, Ts, unifier) = |
884 val (ts, Ts, unifier) = |
884 TypeInfer.infer_types prt prT const_type classrel arities used freeze |
885 TypeInfer.infer_types prt prT const_type classrel arities used freeze |
885 q_is_param raw_ts' pat_Ts'; |
886 is_param raw_ts' pat_Ts'; |
886 in |
887 in |
887 (ts, unifier) |
888 (ts, unifier) |
888 end; |
889 end; |
889 |
890 |
890 |
891 |