![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
When working in .NET, it can be awkward to figure out whether two
objects are "equal". With reference types, two variables might
refer to the same object on the heap, or to two different objects
with identical properties. In the picture below, changing Snail
C's shirt would also change Snail B's, because they are the same
snail, while the otherwise identical Snail A is unchanged.
Value types are more like C structs. So giving Snail C a jacket
and hat does not affect Snail B. It wouldn't make sense to do a
"reference comparison" on a value type; the objects are always
stored in different places (setting aside explicit pointers to
objects in memory, of course - something C# also allows for).

Immutable types with built-in structural equality checks are a great way to work around this issue, but there's still the question of what to do for collection types - the standard .NET HashSet, List and Array types aren't immutable, and even ImmutableList and ImmutableSet don't consider two lists or two sets with the same items to be "equal". But there's a very easy way to handle this problem: you can use the collection types in the F# standard library (FSharp.Core), even without using F#.
( Read more... )