@@ -13,16 +13,23 @@ module private ShallowEqualityHelpers =
1313 let inline hash ( a : 'a ) = ( a :> obj) .GetHashCode()
1414
1515type ShallowEqualityComparer < 'a > private () =
16- static let instance = ShallowEqualityComparer< 'a>() :> System.Collections.Generic.IEqualityComparer< 'a>
16+ static let mutable instance =
17+ { new System.Collections.Generic.IEqualityComparer< 'a> with
18+ member x.GetHashCode v = ShallowEqualityHelpers.hash v
19+ member x.Equals ( a , b ) = ShallowEqualityHelpers.equals a b
20+ }
1721
1822 static member Instance = instance
23+
24+ static member Set ( newInstance : System.Collections.Generic.IEqualityComparer < 'a >) =
25+ instance <- newInstance
1926
20- static member ShallowHashCode v = ShallowEqualityHelpers.hash v
21- static member ShallowEquals ( a , b ) = ShallowEqualityHelpers.equals a b
27+ static member ShallowHashCode v = instance.GetHashCode v
28+ static member ShallowEquals ( a , b ) = instance.Equals ( a , b )
2229
2330 interface System.Collections.Generic.IEqualityComparer< 'a> with
24- member x.GetHashCode v = ShallowEqualityHelpers.hash v
25- member x.Equals ( a , b ) = ShallowEqualityHelpers.equals a b
31+ member x.GetHashCode v = instance.GetHashCode v
32+ member x.Equals ( a , b ) = instance.Equals ( a , b )
2633
2734#else
2835open System.Reflection .Emit
@@ -172,15 +179,22 @@ type ShallowEqualityComparer<'a> private() =
172179 else
173180 fun ( a : 'a ) ( b : 'a ) -> System.Object.ReferenceEquals( a :> obj, b :> obj)
174181
175- static let instance = ShallowEqualityComparer< 'a>() :> System.Collections.Generic.IEqualityComparer< 'a>
182+ static let mutable instance =
183+ { new System.Collections.Generic.IEqualityComparer< 'a> with
184+ member x.GetHashCode v = getHashCode v
185+ member x.Equals ( a , b ) = equals a b
186+ }
176187
177188 static member Instance = instance
178189
179- static member ShallowHashCode v = getHashCode v
180- static member ShallowEquals ( a , b ) = equals a b
190+ static member Set ( newInstance : System.Collections.Generic.IEqualityComparer < 'a >) =
191+ instance <- newInstance
192+
193+ static member ShallowHashCode v = instance.GetHashCode v
194+ static member ShallowEquals ( a , b ) = instance.Equals( a, b)
181195
182196 interface System.Collections.Generic.IEqualityComparer< 'a> with
183- member x.GetHashCode v = getHashCode v
184- member x.Equals ( a , b ) = equals a b
197+ member x.GetHashCode v = instance.GetHashCode v
198+ member x.Equals ( a , b ) = instance.Equals ( a , b )
185199
186200#endif
0 commit comments