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

Automatically deriving instances #945

Open
midfield opened this issue Jun 9, 2022 · 1 comment
Open

Automatically deriving instances #945

midfield opened this issue Jun 9, 2022 · 1 comment
Labels
shovel-ready design is done, just need to build it

Comments

@midfield
Copy link

midfield commented Jun 9, 2022

Similar to Haskell's deriving Eq et al, it would be nice to be able to derive boilerplate type class implementations.

See https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/deriving.html

@dougalm
Copy link
Collaborator

dougalm commented Feb 15, 2023

Yes, let's do it. I suggest we make it more like Haskell's "standalone deriving" at first because it will be simpler to implement if the compiler isn't responsible for figuring out what constraints are required. If the feature is able to derive superclasses automatically, in the spirit of #481, then there'll be less boilerplate anyway - e.g. you just write deriving Monoid instead of deriving (Monoid, Semigroup).

User-defined ADTs are implemented as a "newtype" wrapper around an underlying representation of sums and products, so the mechanism for deriving can just look for instances for those representations and adapt them accordingly. Rather than trying to insert appropriate coercions in the method implementations, let's just add another case to DictExpr, DictExpr n = ... | NewtypeDict (DictType n) (DictExpr n). Then when we actually project out the methods in simplification, the newtype coercion becomes a no-op.

@dougalm dougalm added the shovel-ready design is done, just need to build it label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shovel-ready design is done, just need to build it
Projects
None yet
Development

No branches or pull requests

2 participants