Override comparison for F# set

Posted by Mauricio Scheffer on Stack Overflow See other posts from Stack Overflow or by Mauricio Scheffer
Published on 2010-04-03T17:39:40Z Indexed on 2010/04/03 17:43 UTC
Read the original article Hit count: 345

Filed under:

Is there any way to override the comparison function in a F# set?

I don't see any set construction functions that take a IComparer<T> or comparison function:

  • Set.ofSeq et al don't take a comparison function
  • FSharpSet(IComparer<T> comparer, SetTree<T> tree) constructor is internal, because
  • SetTree is internal and
  • SetTreeModule.ofSeq<a>(IComparer<a> comparer, IEnumerable<a> c) is obviously internal too.

My actual problem is that I have a set of ('a * 'a) and I want a comparison such that for example (1,3) = (3,1).

I know I could wrap this in a type implementing IComparable<T>, but is there any way to avoid this?

© Stack Overflow or respective owner

Related posts about F#