RFC: custom recursors
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Proposal
In a language that compiles pattern matching down to recursor theroems, it seems natural to be able to define custom recursors and have pattern matching and induction work just as before. Here are some use-cases (and I invite interested parties to expand):
-
Arrays as stacks.
I switched some code that was maintaining a stack from using Lists to arrays for performance reasons, and going from pattern matching to
if … then … elseandisEmptyandpopandbackmade it more ugly. It would be great if I could somehow use patterns.emptyand.snoc xs s(possibly with nicer syntax) inmatchstatements.o -
Fin n.This is defined as a subtype of
Nat, which is a nice definitions. But some programs and proofs would benefit from being able to pattern match on theFin ndirectly.In fact, there are two possible recursions that might be useful useful here (going from 0 up, or going from the last one down, changing
nalong the way). It would be good to have both. -
Refactoring.
The
List.Forall₂predicate is defined inductively. It could have been defined recursively over the input lists, which would provide us with some (presumably) nice defeqs. But such a change would affect a lot of code – unless one could prove the existing constructors and induction principle with the new definition and set it up so thatby inductionandmatchwork as before.
TODO (help welcome): Propose concrete syntax/commands/semantics.
Community Feedback
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 with the proposal and its linked community feedback on inductive Fin n and refactoring List.Forall₂. Define concrete syntax, commands, and semantics for custom recursors, with pattern matching and induction continuing to work as described; the issue does not name implementation files or tests.
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
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100