I'm making my way through Functional Programming in Lean and there's an exercise to implement zip
, which takes two lists and returns a list of tuples the length of the shorter of the two input lists. This is my attempt:
def zip {α β : Type} (as: List α) (bs: List β) : List (α × β) :=
match (as, bs) with
| (a::arest, b::brest) => (a, b) :: zip arest brest
| _ => []
This seems clearly correct to me, but Lean gives me this cryptic error:
fail to show termination for
zip
with errors
argument #3 was not used for structural recursion
failed to eliminate recursive application
zip arest brest
argument #4 was not used for structural recursion
failed to eliminate recursive application
zip arest brest
structural recursion cannot be used
failed to prove termination, use `termination_by` to specify a well-founded relation
I'm recursing on both of the inductive arguments at once, so to me this clearly terminates.
What do arguments #3 and #4 refer in the error messages refer to, and how do I convince Lean that this definitely terminates?