Thomas
Thomas

Reputation: 12127

I do not understand this warning: The method or function should not be given explicit type argument(s)

I have this code:

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] 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?

Upvotes: 1

Views: 85

Answers (1)

Brian Berns
Brian Berns

Reputation: 17088

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)

Upvotes: 2

Related Questions