Add a "param handler" to demand_fn for use in automatic type parameter instantiation
This commit is contained in:
parent
ff9ecc1128
commit
de5c6f111c
@ -153,7 +153,11 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
|
|||||||
Ast.TY_rec ty_rec -> ty_rec
|
Ast.TY_rec ty_rec -> ty_rec
|
||||||
| ty -> type_error "record" ty
|
| ty -> type_error "record" ty
|
||||||
in
|
in
|
||||||
let demand_fn (arg_tys:Ast.ty option array) (actual:Ast.ty) : Ast.ty =
|
let demand_fn
|
||||||
|
?param_handler:(param_handler=demand)
|
||||||
|
(arg_tys:Ast.ty option array)
|
||||||
|
(actual:Ast.ty)
|
||||||
|
: Ast.ty =
|
||||||
let expected = lazy begin
|
let expected = lazy begin
|
||||||
Format.fprintf Format.str_formatter "fn(";
|
Format.fprintf Format.str_formatter "fn(";
|
||||||
let print_arg_ty i arg_ty_opt =
|
let print_arg_ty i arg_ty_opt =
|
||||||
@ -173,7 +177,10 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
|
|||||||
type_error (Lazy.force expected) ty;
|
type_error (Lazy.force expected) ty;
|
||||||
let in_slot_tys = Array.map get_slot_ty in_slots in
|
let in_slot_tys = Array.map get_slot_ty in_slots in
|
||||||
let maybe_demand a_opt b =
|
let maybe_demand a_opt b =
|
||||||
match a_opt with None -> () | Some a -> demand a b
|
match a_opt, b with
|
||||||
|
None, _ -> ()
|
||||||
|
| Some a, Ast.TY_param _ -> param_handler a b
|
||||||
|
| Some a, _ -> demand a b
|
||||||
in
|
in
|
||||||
Common.arr_iter2 maybe_demand arg_tys in_slot_tys;
|
Common.arr_iter2 maybe_demand arg_tys in_slot_tys;
|
||||||
get_slot_ty (ty_sig.Ast.sig_output_slot)
|
get_slot_ty (ty_sig.Ast.sig_output_slot)
|
||||||
@ -497,6 +504,12 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
|
|||||||
| TYPAT_fn arg_tys, LTYPE_mono actual ->
|
| TYPAT_fn arg_tys, LTYPE_mono actual ->
|
||||||
ignore (demand_fn (Array.map (fun ty -> Some ty) arg_tys) actual);
|
ignore (demand_fn (Array.map (fun ty -> Some ty) arg_tys) actual);
|
||||||
yield_ty actual
|
yield_ty actual
|
||||||
|
| TYPAT_fn _, LTYPE_poly (_, _) ->
|
||||||
|
(* FIXME: auto-instantiate *)
|
||||||
|
Common.unimpl
|
||||||
|
None
|
||||||
|
"instantiation of polymorphic function types; please supply type \
|
||||||
|
parameters explicitly, sorry"
|
||||||
| TYPAT_wild, (LTYPE_poly _ as lty) ->
|
| TYPAT_wild, (LTYPE_poly _ as lty) ->
|
||||||
Common.err
|
Common.err
|
||||||
None
|
None
|
||||||
@ -504,19 +517,12 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
|
|||||||
type '%a'; supply type parameters explicitly"
|
type '%a'; supply type parameters explicitly"
|
||||||
sprintf_ltype lty
|
sprintf_ltype lty
|
||||||
| TYPAT_ty expected, (LTYPE_poly _ as lty) ->
|
| TYPAT_ty expected, (LTYPE_poly _ as lty) ->
|
||||||
(* FIXME: auto-instantiate *)
|
Common.err
|
||||||
Common.unimpl
|
|
||||||
None
|
None
|
||||||
"sorry, automatic polymorphic instantiation of %a to %a isn't \
|
"not enough context to automatically instantiate '%a' to '%a'; \
|
||||||
supported yet; please supply type parameters explicitly"
|
please supply type parameters explicitly"
|
||||||
sprintf_ltype lty
|
sprintf_ltype lty
|
||||||
Ast.sprintf_ty expected
|
Ast.sprintf_ty expected
|
||||||
| TYPAT_fn _, (LTYPE_poly _) ->
|
|
||||||
(* FIXME: auto-instantiate *)
|
|
||||||
Common.unimpl
|
|
||||||
None
|
|
||||||
"sorry, automatic polymorphic instantiation of function types \
|
|
||||||
isn't supported yet; please supply type parameters explicitly"
|
|
||||||
| _, LTYPE_module _ ->
|
| _, LTYPE_module _ ->
|
||||||
Common.err None "can't refer to a module as a first-class value"
|
Common.err None "can't refer to a module as a first-class value"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user