我不明白此警告:不应为方法或函数提供显式类型参数 [英] 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)
但是在编译时,出现此错误:
but when compiling, I get this error:
[FS0686]不应为方法或函数反序列化"赋予显式类型参数,因为它没有显式声明其类型参数
[FS0686] The method or function 'deserialize' should not be given explicit type argument(s) because it does not declare its type parameters explicitly
该警告发生两次,每次反序列化"使用一次
the warning happens two times, one for each use of 'deserialize'
我不明白此错误,有人可以解释吗?
I don't understand this error, can someone explain?
推荐答案
我认为这里的问题是反序列化
指的是您尚未使用的类型'b
在任何地方定义.要解决此问题,您应该将 deserialize
移到顶层,并显式声明'b
.像这样:
I think the problem here is that deserialize
refers to a type 'b
that you haven't defined anywhere. To fix this, you should move deserialize
out to the top level and declare 'b
explicitly. Something like this:
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)
这篇关于我不明白此警告:不应为方法或函数提供显式类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!