Skip to content
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

Improve Eq Hs instances #348

Merged
merged 2 commits into from
Jan 8, 2025
Merged

Improve Eq Hs instances #348

merged 2 commits into from
Jan 8, 2025

Conversation

TravisCardwell
Copy link
Collaborator

I received feedback about how Vec.withDict can be used to recover the SNatI dictionary of a Vec, and using it makes adding SNatI many constraints unnecessary. Thank you @sheaf!

I also received feedback about using GEq. Thank you @phadej!

This commit refactors the changes made to commit "Add Hs AST Eq instances, test using tree-diff" (916ab6db). It removed all added SNatI constraints and uses GEq instances.

An unsightly aspect of the refactored code is the use of auxiliary functions just to bring type variables that are not part of the type signature in scope, but I do not know of a way to do this otherwise.

hs-bindgen/src/HsBindgen/C/AST/Macro.hs Show resolved Hide resolved
hs-bindgen/src/HsBindgen/Hs/AST.hs Show resolved Hide resolved
hs-bindgen/src/HsBindgen/Hs/AST.hs Outdated Show resolved Hide resolved
hs-bindgen/src/HsBindgen/Hs/AST.hs Outdated Show resolved Hide resolved
hs-bindgen/src/HsBindgen/Hs/AST.hs Outdated Show resolved Hide resolved
hs-bindgen/src/HsBindgen/Hs/AST.hs Outdated Show resolved Hide resolved
hs-bindgen/src/HsBindgen/Hs/AST.hs Outdated Show resolved Hide resolved
TravisCardwell added a commit that referenced this pull request Jan 6, 2025
The `Size` can be deduced from `Vec n NameHint`.  This change moves the
`induction` closer to where it is used.
Copy link
Collaborator

@edsko edsko left a comment

Choose a reason for hiding this comment

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

Reviewed over meet. Feel free to merge after making the changes discussed.

@phadej
Copy link
Collaborator

phadej commented Jan 8, 2025

I think we shouldn't need Eq instances at all. This is all ugly and tedious code, and also error prone one.

@edsko
Copy link
Collaborator

edsko commented Jan 8, 2025

@phadej I think we got started on this path due to the Eq requirement of ediffGolden1. Can that be avoided?

@phadej
Copy link
Collaborator

phadej commented Jan 8, 2025

@edsko, yes, https://hackage.haskell.org/package/tree-diff-0.3.4 does exactly that.

I feel ashamed that I didn't notice that (and disappointed that nobody else either) for the seven years package existed.

I received feedback about how `Vec.withDict` can be used to recover the
`SNatI` dictionary of a `Vec`, and using it makes adding `SNatI` many
constraints unnecessary.  Thank you @sheaf!

I also received feedback about using `GEq`.  Thank you @phadej!

This commit refactors the changes made to commit "Add Hs AST Eq
instances, test using tree-diff" (`916ab6db`).  It removed all added
`SNatI` constraints and uses `GEq` instances.

An unsightly aspect of the refactored code is the use of auxiliary
functions just to bring type variables that are not part of the type
signature in scope, but I do not know of a way to do this otherwise.
Based on feedback/guidance from @sheaf, `equals` from
`HsBindgen.Util.TestEquality` and a new `ApEq` wrapper are used to
significantly simplify the instance definitions.  With a new `geqVec`
function, auxiliary functions that just bring type variables into scope
are no longer needed.  Thank you @sheaf!
@TravisCardwell
Copy link
Collaborator Author

Implementing the Eq instances has been educational for me, at least. I will go ahead and merge this commit and remove the Eq instances in a separate PR for #351.

Thank you for the update to tree-diff!

@TravisCardwell TravisCardwell merged commit aa82f60 into main Jan 8, 2025
10 checks passed
@TravisCardwell TravisCardwell deleted the hs-eq-instances branch January 8, 2025 21:23
TravisCardwell added a commit that referenced this pull request Jan 8, 2025
This commit removes the Eq instances that were added in the following
commits:

* `916ab6dc` Add Hs AST Eq instances, test using tree-diff
* `a02d5d28` Improve Eq Hs instances
* `5243b337` Improve Eq Hs instances (2)

Note that `ApEq` in `HsBindgen.Util.TestEquality` is *not* removed.

Discussion: #348
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.

4 participants