Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:46:32+00:00 2026-06-13T13:46:32+00:00

F# supports structural equality of two-dimensional arrays with the = operator, and in F#

  • 0

F# supports structural equality of two-dimensional arrays with the = operator, and in F# collections such as Set. But how can I use the same equality comparison in the .NET class HashSet? By default it uses referential equality, and although there is a constructor that takes an instance of IEqualityComparer<T> I cannot find a suitable built-in instance for two-dimensional arrays.

I looked at System.Collections.StructuralComparisons.StructuralEqualityComparer, but that seems to have two problems. Firstly, it is not generic, and secondly, it does not seem to support two-dimensional arrays:

> let xss = Array2D.create 2 2 99;;
> let yss = Array2D.create 2 2 99;;

// `=` operator does what I want
> xss = yss;;
val it : bool = true

// pre-defined StructuralEqualityComparer object doesn't work
> open System.Collections;;
> let comp = StructuralComparisons.StructuralEqualityComparer;;
val comp : IEqualityComparer
> (xss :> 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 <StartupCode$FSI_0023>.$FSI_0023.main@()

Ultimately, I’d like to fix the following code so that it returns 1, not 2:

> let hashset = new Generic.HashSet<int[,]>();;
> hashset.Add xss;;
> hashset.Add yss;;
> hashset.Count;;
val it : int = 2

I would also be happy with a solution using Dictionary, but I think the same issues apply.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:46:33+00:00Added an answer on June 13, 2026 at 1:46 pm
    let a = Array2D.create 2 2 99
    let b = Array2D.create 2 2 99
    let set = System.Collections.Generic.HashSet(HashIdentity.Structural)
    set.Add a
    set.Add b
    printfn "%A" set.Count // 1
    

    Online demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If a language has control structures and variables, but no support for arrays, lists,
Asciidoc supports callouts . How can one write similar callouts using reStructuredText ?
Can someone tell me which data structure supports insert/delete/maximum operation in O(1)?
Can someone recommend a reliable HTML tree control that also supports tree manipulation? I
according to msdn IStructuralEquatable Defines methods to support the comparison of objects for structural
What data structure supports the following set operations efficiently both in time and space?
I know that a structure can be defined by in several ways such as:
On shared web-hosting my software supports multiple domains (all domains point to the same
I need to design a data structure that supports the following operations: search element
Spring supports programmatic transaction which give us fine grained control over TX management. According

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.