Steps required to reproduce the problem
typeTest<'Twhen'T:>INumber<'T>>={ One:'T;
Two:'T; Three:'T }withmemberthis.ThreeSum= this.One + this.Two + this.Three Expected behavior
Compiles
Actual behavior
error FS0670: This code is not sufficiently generic. The type variable ^T when ^T :> INumber<^T> could not be generalized because it would escape its scope.
Known workarounds
Intermediate member or using type-defined methods:
typeTest<'Twhen'T:>INumber<'T>>={ One:'T;
Two:'T; Three:'T }withmemberthis.TwoSum= this.One + this.Two
memberthis.ThreeSum= this.TwoSum + this.Three
memberthis.ThreeSum1= 'T.op_CheckedAddition('T.op_CheckedAddition(this.One, this.Two), this.Three)Related information
Provide any related information (optional):
- Operating system: Windows 11
- .NET Runtime kind (.NET Core, .NET Framework, Mono)
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.8d38d0cc - Editing Tools Rider/CLI
Extra notes
inline member with + constraint works:
typeTest1<'Twhen'T:(static member(+):'T->'T->'T)>={ One:'T;
Two:'T; Three:'T }withmember inlinethis.TwoSum= this.One + this.Two + this.ThreeBut similar approach with INumber<> fails:
type Test<'T when 'T:> INumber<'T>> = { One: 'T;
Two: 'T; Three: 'T } with
member inline this.ThreeSum1 = this.One + this.Two - this.Three
error FS0339: The signature and implementation are not compatible because the type parameter in the class/signature has a different compile-time requirement to the one in the member/implementation
Steps required to reproduce the problem
Expected behavior
Compiles
Actual behavior
Known workarounds
Intermediate member or using type-defined methods:
Related information
Provide any related information (optional):
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.8d38d0cc
Extra notes
inline member with
+constraint works:But similar approach with
INumber<>fails: