How does set1 = set2
for F# immutable sets and maps work? Will they do proper set/map equality?
The documentation says:
Immutable sets based on binary trees, where comparison is the F# structural comparison function, potentially using implementations of the IComparable interface on key values.
They are based on binary trees, so might not the exact form depending on the order elements were inserted? So naively using the F# structural comparison function would not work...
I can't find anything about it in the documentation. Have I just missed it?
Yes, it will work properly, apparently.
Looking at the source, Equals
is overridden and uses GetEnumerator
and checks that these return the same elements in the same order. These should be in-order as seen in this question, since the doc for Set.toSeq
says: "An ordered sequence of the elements of set."
This is also mentioned in the book "F# for Scientists" by Jon Harrop and Don Syme:
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