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

Deriving Eq #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Deriving Eq #148

wants to merge 2 commits into from

Conversation

janmasrovira
Copy link
Contributor

Replaces the existing Eq instance of some types by a deriving instance.

janmasrovira added a commit to anoma/juvix that referenced this pull request Nov 22, 2024
This pr adds automatic implementation of `Eq` instances for inductive
types. To create such an instance the user will use the same syntax as a
regular instance with two differences.
1. It is prefixed with the `deriving` keyword.
2. It has no body.

E.g. 
```
deriving instance
eqProductI {A B} {{Eq A}} {{Eq B}} : Eq (Pair A B);
```

This desugars into an instance that returns true when the constructors
match and all arguments are equal according to their respective
instances. There is no special handling of type errors occurring in the
generated code. I.e. if the user forgets a necessary instance argument
in the type signature, a type error will occur in the generated code.

## Stdlib PR
- anoma/juvix-stdlib#148

# Future work
* In the future we should look at
https://www.dreixel.net/research/pdf/gdmh_nocolor.pdf
* See also:
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/generic-deriving

---------

Co-authored-by: Lukasz Czajka <[email protected]>
@janmasrovira janmasrovira force-pushed the deriving-eq branch 2 times, most recently from 9534bd2 to f0a1e1e Compare November 28, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants