When I try to create some class like
type MyType () =
let func<'T> () = ()
The compiler says that there’s an error:
error FS0665: Explicit type parameters may only be used on
module or member bindings
But the MSDN says:
A let binding at the module level, in a type, or in a computation expression can have explicit type parameters. A let binding in an expression, such as within a function definition, cannot have type parameters.
Why documentation and compiler say different things?
This appears to be a syntactic restriction on
letbindings inside a class. However, you can still define a generic local function, you just have to specify the type parameters in type annotations:I do not think this is explicitly syntactically forbidden by the specification, because the specification says that a class definition has the following structure:
and class-or-value-defn is defined as:
where function-or-value-defns may be a function definition with explicit type parameters: