我不明白这个警告:不应为方法或函数提供显式类型参数
I do not understand this warning: The method or function should not be given explicit type argument(s)
我有这个代码:
type BSCReply =
{
status: int
message: string
result: string
}
let private decodeResult<'a> (result: IRestResponse) =
let deserialize content =
try
Ok (JsonConvert.DeserializeObject<'b> content)
with ex ->
Error (HttpStatusCode.InternalServerError, ex.Humanize())
match result.IsSuccessful with
| true -> match deserialize<BSCReply> result.Content with
| Ok r -> deserialize<'a> r.result
| Error e -> Error e
| false -> Error(result.StatusCode, result.ErrorMessage)
但是在编译时,我得到这个错误:
[FS0686] The method or function 'deserialize' should not be given explicit type argument(s) because it does not declare its type parameters explicitly
警告出现两次,每次使用 'deserialize'
我不明白这个错误,谁能解释一下?
我认为这里的问题是 deserialize
指的是您未在任何地方定义的类型 'b
。要解决此问题,您应该将 deserialize
移到顶层并明确声明 'b
。像这样:
let private deserialize<'b> content =
try
Ok (JsonConvert.DeserializeObject<'b> content)
with ex ->
Error (HttpStatusCode.InternalServerError, ex.Humanize())
let private decodeResult<'a> (result: IRestResponse) =
match result.IsSuccessful with
| true -> match deserialize<BSCReply> result.Content with
| Ok r -> deserialize<'a> r.result
| Error e -> Error e
| false -> Error(result.StatusCode, result.ErrorMessage)
我有这个代码:
type BSCReply =
{
status: int
message: string
result: string
}
let private decodeResult<'a> (result: IRestResponse) =
let deserialize content =
try
Ok (JsonConvert.DeserializeObject<'b> content)
with ex ->
Error (HttpStatusCode.InternalServerError, ex.Humanize())
match result.IsSuccessful with
| true -> match deserialize<BSCReply> result.Content with
| Ok r -> deserialize<'a> r.result
| Error e -> Error e
| false -> Error(result.StatusCode, result.ErrorMessage)
但是在编译时,我得到这个错误:
[FS0686] The method or function 'deserialize' should not be given explicit type argument(s) because it does not declare its type parameters explicitly
警告出现两次,每次使用 'deserialize'
我不明白这个错误,谁能解释一下?
我认为这里的问题是 deserialize
指的是您未在任何地方定义的类型 'b
。要解决此问题,您应该将 deserialize
移到顶层并明确声明 'b
。像这样:
let private deserialize<'b> content =
try
Ok (JsonConvert.DeserializeObject<'b> content)
with ex ->
Error (HttpStatusCode.InternalServerError, ex.Humanize())
let private decodeResult<'a> (result: IRestResponse) =
match result.IsSuccessful with
| true -> match deserialize<BSCReply> result.Content with
| Ok r -> deserialize<'a> r.result
| Error e -> Error e
| false -> Error(result.StatusCode, result.ErrorMessage)