Data.List.getLast
is defined as follows:
def getLast : ∀ (as : List α), as ≠ [] → α
| [], h => absurd rfl h
| [a], _ => a
| _::b::as, _ => getLast (b::as) (fun h => List.noConfusion h)
I do not understand this definition, in particular the details around the recursive call.
- Why is the last argument a lambda, when the signature seems to suggest a proof?
- What is List.noConfusion, where is it defined, and how does it relate to the "No Confusion" rule in general?
- Here's the type of List.noConfusion:
List.noConfusion.{u_1, u} {α : Type u} {P : Sort u_1} {v1 v2 : List α} (h12 : v1 = v2) : List.noConfusionType P v1 v2
How should I interpreter this? What is noConfusionType?
List.noConfusion
is generated automatically by Lean 4 when you makeList
. $\endgroup$List.noConfusion
is defined see this answer: proofassistants.stackexchange.com/a/1664/122. However it is slightly different in Lean 4. Namely these automatic theorems are hidden until they are used by some automation in Lean, likesimp
or what you are seeing. $\endgroup$List.getLast
. NoData
. $\endgroup$