我在F#試圖創建一個通用的接口,它的類型參數必須支持另外,讓我結束了這樣的事情:通用接口,其中類型參數支持另外
type IMyInterface<'b when 'b : (static member (+) : 'b * 'b -> 'b)> =
abstract member myFunction : 'b -> 'b
不幸的是這片代碼給我下面的錯誤:
This code is not sufficiently generic. The type variable ^D when ^D : comparison and ^D : (static member (+) : ^D * ^D -> ^D) could not be generalized because it would escape its scope.
我發現this question對於同樣的問題,但我不知道我的理解爲什麼功能已被標記爲inline
。
而且,因爲你不能讓一個抽象的成員inline
,也存在另一種解決方案,我可以在我的具體的例子使用?還是我必須找到一個完整的方法來實現這個目標?