Skip to content

Add sameSmallArray and sameSmallMutableArray#441

Open
sjakobi wants to merge 2 commits intohaskell:masterfrom
sjakobi:feature/same-smallarray-wrappers
Open

Add sameSmallArray and sameSmallMutableArray#441
sjakobi wants to merge 2 commits intohaskell:masterfrom
sjakobi:feature/same-smallarray-wrappers

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Feb 6, 2026

Resolves #403.

@sjakobi
Copy link
Member Author

sjakobi commented Feb 6, 2026

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# =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the Eq instance for SmallArray not be similarly cleaned up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, short-circuiting was the desired cleanup. Thank you!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Floating point is indeed a problem... Did @sjakobi do some recent pointer equality stuff in unordered-containers, or did @meooow25 do it in containers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrapper for sameSmallMutableArray#

4 participants