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.ofSeqet al don’t take a comparison functionFSharpSet(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?
I think the
settype available in F# core libraries doesn’t allow specifying your own comparison. However, there is a tagged version of the type in PowerPack that allows this. The following shows how to create a set with comparer that compares integers using modulo 10: