I propose we allow a class that implements just the generic IComparable<'T> interface, satisfy the comparison constraint.
The existing way of approaching this problem in F# is by implementing the non-generic interface IComparable (or IStructuralComparable). However this approach is not ideal, because it requires a type cast (and potentially unboxing) of a value of type obj. Implementing all three interfaces would increase boilerplate code even more.
Pros and Cons
The advantages of making this adjustment to F# are increased ease of defining a custom comparison function, and conformity to modern coding practices by using generic interfaces.
The disadvantages of making this adjustment to F# are none, I guess. As for backwards compatibility, we can provide an automatic implementation of the two non-generic interfaces, if there are not specified.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: The issue was first reported in dotnet/fsharp#7945.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
I propose we allow a class that implements just the generic
IComparable<'T>interface, satisfy thecomparisonconstraint.The existing way of approaching this problem in F# is by implementing the non-generic interface
IComparable(orIStructuralComparable). However this approach is not ideal, because it requires a type cast (and potentially unboxing) of a value of typeobj. Implementing all three interfaces would increase boilerplate code even more.Pros and Cons
The advantages of making this adjustment to F# are increased ease of defining a custom comparison function, and conformity to modern coding practices by using generic interfaces.
The disadvantages of making this adjustment to F# are none, I guess. As for backwards compatibility, we can provide an automatic implementation of the two non-generic interfaces, if there are not specified.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: The issue was first reported in dotnet/fsharp#7945.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply: