I have a stupid problem, I need to implement in F# class the interface which have following method:
public interface IMyInterface
{
T MyMethod<T>() where T : class;
}
And I am struggling myself doing it in F#. I have tried different ways. But the problem is that an object of type T must be returned. Null is not accepted:
type public Implementation() =
interface IMyInterface with
member this.MyMethod<'T when 'T : not struct>() = null
Error: The member 'MyMethod<'T when 'T : not struct> : unit -> a' when a': not struct and 'a: null does not have the correct type to override the corresponding abstract method. The required signature is 'MyMethod<'T when 'T : not struct> : unit -> 'T when 'T: not struct'
So I have tried to put T as argument to the class, but still no I finished with error:
type public Implementation(data : 'T when 'T : not struct) =
interface IMyInterface with
member this.MyMethod<'T when 'T : not struct>() = data
Error: The member 'MyMethod<'T when 'T : not struct> : unit -> 'T when 'T : not struct' does not have the correct type to override the corresponding abstract method.
Thank you for help.