Add sameSmallArray and sameSmallMutableArray#441
Add sameSmallArray and sameSmallMutableArray#441sjakobi wants to merge 2 commits intohaskell:masterfrom
Conversation
|
The windows-latest and macos-latest CI jobs fail because primitive's bounds aren't compatible with GHC 9.14 yet. #440 seems to address this. |
| @@ -525,7 +549,7 @@ instance Eq a => Eq (SmallArray a) where | |||
|
|
|||
| instance Eq (SmallMutableArray s a) where | |||
| SmallMutableArray sma1# == SmallMutableArray sma2# = | |||
There was a problem hiding this comment.
Can the Eq instance for SmallArray not be similarly cleaned up?
There was a problem hiding this comment.
As opposed to the instance for SmallMutableArray, the instance for SmallArray can return True, when the arrays are not in the same memory location, but have same the elements. We can use sameSmallArray to enable short-circuiting though! :)
There was a problem hiding this comment.
Yeah, short-circuiting was the desired cleanup. Thank you!
There was a problem hiding this comment.
There's problem with floating point and lawless Eq instances. With sameSmallArray shortcut
let x=[nan] in x==x returns True but let x=[nan]; y=[nan] in x==y returns False.
There was a problem hiding this comment.
There's problem with floating point and lawless Eq instances. With sameSmallArray shortcut
let x=[nan] in x==xreturns True butlet x=[nan]; y=[nan] in x==yreturns False.
Floating point is indeed a problem... Did @sjakobi do some recent pointer equality stuff in unordered-containers, or did @meooow25 do it in containers?
There was a problem hiding this comment.
Hmm. This is unfortunate, but I think it's acceptable that broken Eq instances don't interact well with the Eq instances of container types. Users can still resort to liftEq (==) if necessary.
There was a problem hiding this comment.
Did @sjakobi do some recent pointer equality stuff in
unordered-containers,
I did some, but I don't think it affects the Eq instances for HashMap or HashSet.
There was a problem hiding this comment.
Did @sjakobi do some recent pointer equality stuff in
unordered-containers,I did some, but I don't think it affects the
Eqinstances forHashMaporHashSet.
Oh right, some bulk operation stuff. Regardless, we might want to document that floating point NaNs are not suitable for use as keys, If we haven't already.
Use sameSmallArray to short-circuit (==) when two SmallArray values share the same underlying object.
Resolves #403.