By default, tuples, dis­crim­i­nated unions and records have what is known as struc­tural equal­ity – i.e. if two instances of these types have the same set of val­ues then they are con­sid­ered equal, just like value types – despite being ref­er­ence types:

Tuples

image

Dis­crim­i­nated Unions

image

Records

image

To facil­i­tate this form of equal­ity, the F# com­piler auto­mat­i­cally over­rides Object.Equals and Object.GetHashCode meth­ods for you. How­ever, there may be times when you want to use ref­er­en­tial equal­ity with these types, in which case you just need to add the Ref­er­enceE­qual­ity attribute to your type:

image

Share