This is apparently the syntactic restriction on let binding inside the class. However, you can still define a common local function, you just need to specify the type parameters in the type annotations:
type MyType () = let func (x : 'T) : 'T = x
I do not think this is explicitly syntactically forbidden by the specification, because the specification states that the class definition has the following structure:
type type-name patopt as-defnopt =
class inherits-Decl <sub> non-automatic sub>
Class-function or-valuation defns <sub> non-automaticSub>
Defn type
and class-or-value-defn is defined as:
class-function-or-value-defn: = attributes opt static opt let rec opt function- or cost, defns
where function-or-value-defns can be a function definition with explicit parameters of the type:
function-defn: =
inline opt access opt ident-or-op typar-defns opt argument-pats return-typeopt = expr
Tomas petricek
source share