It seems one has to override Equality in order to override comparison.
Is it true ? Is there any reason I am missing ?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With