RFC: `deriving` for single field `structure`s
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the deriving framework and reproducing the reported single-field structure example with Add, Sub, Neg, LE, LT, and ToString. Done means those handlers derive successfully for the Offset structure while preserving the existing behavior shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100