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

RFC: deriving for single field structures #6319

Open
hargoniX opened this issue Dec 5, 2024 · 1 comment
Open

RFC: deriving for single field structures #6319

hargoniX opened this issue Dec 5, 2024 · 1 comment
Labels
P-medium We may work on this issue if we find the time RFC accepted RFC is waiting for a corresponding PR (external or internal) RFC Request for comments

Comments

@hargoniX
Copy link
Contributor

hargoniX commented Dec 5, 2024

Proposal

Currently the following program from our time library works and correctly derives all the instances:

def Offset : Type := UnitVal 1
  deriving Repr, BEq, Inhabited, Add, Sub, Neg, LE, LT, ToString

However if we wanted to refactor this to a single field structure to make writing instances such as Decidable for LT easier:

structure Offset : Type where
  val : UnitVal 1
  deriving Repr, BEq, Inhabited, Add, Sub, Neg, LE, LT, ToString

The following deriving handlers:

Add, Sub, Neg, LE, LT, ToString

all fail with:

default handlers have not been implemented yet, class: 'Add' types: [Std.Time.Second.Offset]

Based on some preliminary reading of the deriving framework it seems to me that we have an automated deriving mechanism for all classes for just def but this just gives up on single field structures right away. I propose that we improve this mechanism to allow such automated deriving for all single field structure's as well.

Impact

Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.

@hargoniX hargoniX added the RFC Request for comments label Dec 5, 2024
@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Dec 6, 2024
@Kha
Copy link
Member

Kha commented Dec 6, 2024

RFC accepted!

Note that very much unlike def, we can't just rely on definitional equality but have to transform the existing instance, which in the case of dependencies might not even be possible in general. So this is a pretty complex task and it will likely take some time for us to get to it.

@Kha Kha added the RFC accepted RFC is waiting for a corresponding PR (external or internal) label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-medium We may work on this issue if we find the time RFC accepted RFC is waiting for a corresponding PR (external or internal) RFC Request for comments
Projects
None yet
Development

No branches or pull requests

3 participants