Hi Rob,

In all versions of F# so far, the F# generic equality and inequality operators are implemented via IComparable. Hence to customize the behaviour of "=" you simply have to implement IComparable.

F# does insert an implementation of Object.Equals for record, union and tuple types, and you should do the same if you customize IComparable. That is, implement both Object.Equals and IComparable and ensure they have consistent behaviour.

One reason for doing this is that your types will then work as expected, e.g. with the System.Collections.Generic.Dictionary type.

Another reason is that there have been design change requests to have F# implement "=" by calling Object.Equals rather than going via "compare"/"IComparable". For this reason it's possible that in future versions we may call your implementation of Equals directly. For this and other reasons it's much better to implement both in a consistent way when customizing types.

For hash codes the situation is slightly simpler: juts implementing Object.GetHashCode is always sufficient. (That has been the case since F# 1.9.2.9)

Kind regards

Don

By on 11/26/2007 12:44 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper