Skip to content

Arbitrary instance for HashMap is unfortunate #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
treeowl opened this issue Jun 12, 2017 · 8 comments
Closed

Arbitrary instance for HashMap is unfortunate #154

treeowl opened this issue Jun 12, 2017 · 8 comments

Comments

@treeowl
Copy link
Collaborator

treeowl commented Jun 12, 2017

arbitrary for HashMap k v (in tests/Strictness.hs) is based on fromList. This means that only HashMap shapes that can be produced by fromList will be represented in the inputs to test functions.

@treeowl
Copy link
Collaborator Author

treeowl commented Jun 12, 2017

I looked into trying to improve this myself. Unfortunately, doing so requires a clear understanding of the data structural invariants, which don't seem to be specified in the source.

@tibbe
Copy link
Collaborator

tibbe commented Jun 13, 2017

It's a bit tricky to create valid structures without going via the public API, you essentially have to mirror what insertion does.

@treeowl
Copy link
Collaborator Author

treeowl commented Jun 13, 2017 via email

@tibbe
Copy link
Collaborator

tibbe commented Jun 13, 2017

We should probably not assume that only insertions get you all trees, because there's an implementation option to either collapse unnecessarily deep branches eagerly or lazily on deletion.

@sjakobi
Copy link
Member

sjakobi commented Jul 13, 2020

I just now noticed the work in #157.

@treeowl In #157 (comment) you said

I think we've removed the need for it by removing the representation
redundancy. See the changes in Eq implementation.

Could you expand a bit on this? Which changes does this refer to? Which redundancy was removed?

Do these changes mean that this issue was already fixed?

@treeowl
Copy link
Collaborator Author

treeowl commented Jul 13, 2020

It used to be that certain paths weren't compressed under some circumstances. I don't remember the circumstances. So there could have been multiple tree shapes representing the same map. That meant maps could sometimes get inefficient, and it made the Eq instance less efficient, so we changed it.

@sjakobi
Copy link
Member

sjakobi commented Jul 13, 2020

Thanks! #39 and #193 look related.

Is there any documentation on these invariants? Are they tested?

Seems like something that we'd need to be careful about when addressing #225 or #226.

@sjakobi
Copy link
Member

sjakobi commented May 3, 2022

Since HashMaps have been canonicalized I think we can close this issue now.

@sjakobi sjakobi closed this as completed May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants