leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.72k stars 425 forks source link

Code generator support for recursors #2049

Open eric-wieser opened 1 year ago

eric-wieser commented 1 year ago

Prerequisites

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%

gebner commented 1 year ago

See also the discussion at https://github.com/leanprover/std4/pull/91