title: IEqualityComparer instance for two-dimensional arrays
body: <p>F# supports structural equality of two-dimensional arrays with the <code>=</code> operator, and in F# collections such as <code>Set</code>. But how can I use the same equality comparison in the .NET class <code>HashSet</code>? By default it uses referential equality, and although there is a constructor that takes an instance of <code>IEqualityComparer&lt;T&gt;</code> I cannot find a suitable built-in instance for two-dimensional arrays.</p>
  
  <p>I looked at <code>System.Collections.StructuralComparisons.StructuralEqualityComparer</code>, but that seems to have two problems. Firstly, it is not generic, and secondly, it does not seem to support two-dimensional arrays:</p>
  
  <pre><code>&gt; let xss = Array2D.create 2 2 99;;
  &gt; let yss = Array2D.create 2 2 99;;
  
  // `=` operator does what I want
  &gt; xss = yss;;
  val it : bool = true
  
  // pre-defined StructuralEqualityComparer object doesn't work
  &gt; open System.Collections;;
  &gt; let comp = StructuralComparisons.StructuralEqualityComparer;;
  val comp : IEqualityComparer
  &gt; (xss :&gt; IStructuralEquatable).Equals(yss, comp);;
  System.ArgumentException: Array was not a one-dimensional array.
     at System.Array.GetValue(Int32 index)
     at System.Array.System.Collections.IStructuralEquatable.Equals(Object other, IEqualityComparer comparer)
     at &lt;StartupCode$FSI_0023&gt;.$FSI_0023.main@()
  </code></pre>
  
  <p>Ultimately, I'd like to fix the following code so that it returns 1, not 2:</p>
  
  <pre><code>&gt; let hashset = new Generic.HashSet&lt;int[,]&gt;();;
  &gt; hashset.Add xss;;
  &gt; hashset.Add yss;;
  &gt; hashset.Count;;
  val it : int = 2
  </code></pre>
  
  <p>I would also be happy with a solution using <code>Dictionary</code>, but I think the same issues apply.</p>