I'm getting a VR error on a let binding on module scope saying one of its parameters is a generic, but I don't know why that parameter is generic in the first place. This is the code:
let private asJsonResponse (responseSource: _ Task) =
fun (next: HttpFunc) (ctx: HttpContext) ->
task {
let! consumption = responseSource
return! json consumption next ctx
}
let getVal = someFuncThatReturnsTaskOfMyType() |> asJsonResponse
The error is on the last line:
error FS0030: Value restriction. The value
getVal
has been inferred to have generic typeval getVal: (HttpFunc -> '_a -> Task<HttpContext option>)
when'_a :> HttpContext
Either make the arguments togetVal
explicit or, if you do not intend for it to be generic, add a type annotation.
I understand that it essentially generalizes ctx: HttpContext
to something that can be cast to HttpContext
. Why does this happen? And why only for this parameter and not next: HttpFunc
?
HttpContext
is a class and HttpFunc
is a function type, is that the problem?