Reputation: 9805
It seems one has to override Equality in order to override comparison.
Is it true ? Is there any reason I am missing ?
Upvotes: 7
Views: 3178
Reputation: 754763
No. It is possible to only have custom comparison
[<CustomComparison>]
[<StructuralEquality>]
type Node =
| Data of string
| Nil
with
interface System.IComparable with
member x.CompareTo y = 0
Note though that this code will produce a warning recomending that you implement equality on the type as well. This is generally a good idea. If you go through the trouble of implementing comparison then equality straight forward (Compare == 0).
Upvotes: 8