You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
openSystem[<StructuralEquality; CustomComparison>]typeMyType= MyType ofintwithmemberx.Value=match x with MyType x -> x
interface IComparable<MyType>withmemberx.CompareTo(x')=
compare x.Value x'.Value
letmySet= Set.singleton <| MyType 521
At MyType 521, it presents the following compiler error:
error FS0001: The type 'MyType' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface
MyType however implements the genericIComparable. Why isn't that enough? Shouldn't the compiler provide an automatic implementation for the non-generic interface in cases like that?
On the other hand, the generic IEquatable interface is sufficient for the "equality" constraint.
The text was updated successfully, but these errors were encountered:
This is currently by design - the comparison constraint is satisfied by the System.IComparable interface, not the System.IComparable<'T> interface. I recommend filing a new language suggestion here to propose that the generic interface do this: https://github.com/fsharp/fslang-suggestions/issues
I think the title is descriptive enough.
Code sample:
At
MyType 521
, it presents the following compiler error:MyType
however implements the genericIComparable
. Why isn't that enough? Shouldn't the compiler provide an automatic implementation for the non-generic interface in cases like that?On the other hand, the generic
IEquatable
interface is sufficient for the "equality" constraint.The text was updated successfully, but these errors were encountered: