I have this interface:
type IMovingFunc< 'T > =
abstract member Add : 'T -> unit
Now I want to create a generic type that implements Add function and uses (+) operator:
type MovingSum< ^T >(initial : ^T) =
let mutable sum = initial
interface IMovingFunc< ^T> with
member inline this.Add x = sum <- sum + x
Unfortunately, I'm getting this error:
This code is not sufficiently generic. The type variable ^T when ^T : (static member ( + ) : ^T * ^T -> ^T) could not be generalized because it would escape its scope.
I've tried adding type constraint to MovingSum but it didn't help:
type MovingSum< ^T when ^T : (static member ( + ) : ^T * ^T -> ^T)>(initial : ^T)
Could you please tell me how to fix this or is there other way to achieve this?