liveBook · Manning

Structural equality

As explained in F# in Action: A Revised Edition of Get Programming with F#

Structural equality determines equality by recursively comparing the contents of corresponding values and their nested fields.

Structural equality compares values by recursively checking the data stored in corresponding fields. F# records and tuples support it by default, unlike .NET’s default reference equality. section 5.3.2

Comparing nested records

Two record values containing the same name and address compare as equal: let areTheyTheSame = (isaac = isaacTwo) // true. The check follows nested records, tuples, and other fields until it finds a difference. section 5.3.2

This removes the need to generate equality members manually for common F# record models. When comparing an entire object graph is undesirable, equality and comparison can be disabled or customized with attributes. section 5.3.2

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains default equality, deep field traversal, .NET contrast, and disabling or customizing comparison.
Examples
Compares two equal person records and highlights nested address checking.
What it assumes
Assumes familiarity with records, tuples, and possibly C# classes while contrasting F# defaults.
What you can do after
Evaluate/understand equality between records and tuples without generating comparison code.
How it connects
Links records and tuples with reference equality, .NET, object graphs, and custom equality comparison.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.