leanprover / leanprover/lean4

Code generator support for recursors

Open
#2,049 1 comment 1 reaction 1 assignee View on GitHub

@zwarich is already working on this.

Since Jun 20, 2025.

P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.
Description

I couldn't see a tracking issue for this, so thought I'd create one to refer to from mathlib4.
We quite often use Nat.rec and List.rec, and neither are supported by the code generator:

https://github.com/leanprover/lean4/blob/a125a36bcc79a28963ed5786f94c5d97648a8f99/src/Lean/CoreM.lean#L280-L295

Steps to Reproduce

Run

#eval (List.rec 0 (fun x xs ih => 0) ([] : List Nat) : Nat)

Expected behavior: Prints 0

Actual behavior:

code generator does not support recursor 'List.rec' yet, consider using 'match ... with' and/or structural recursion

Reproduces how often: 100%

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.