In F#, I have defined an interface with a generic member:
type MyType =
abstract MyMember<'a> : 'a -> int
I would like to write a function that can create an object that implements this interface:
module MyType =
let create f =
{
new MyType with
member __.MyMember(x) = f x
}
This currently fails to compile with the following error message:
This code is not sufficiently generic. The type variable 'a could not be generalized because it would escape its scope.
Is it possible to make this work via inlining and static resolved type parameters (or something similar)? Thanks.