有没有一种方法可以从策略模式或 Lean 中的匹配表达式递归调用函数?

Is there a way to call a function recursively from tactic mode or from match expressions in Lean?

尝试 #1:

def sget' {α : Type} {n : ℕ} (i : ℕ) {h1 : n > 0} {h2 : i < n} (s: sstack α n) : α :=
begin
  cases n with n0 nn,
  begin
    have f : false, from nat.lt_asymm h1 h1,
    tauto,
  end,
  induction s,
  cases s_val,
  begin
    have : stack.empty.size = 0, from @stack_size_0 α,
    tauto,
  end,
  cases i with i0 ri,
  exact s_val_x,
  exact sget' (pred i) s_val_s,
end

尝试 #2:

def sget' {α : Type} {n : ℕ} (i : ℕ) {h1 : n > 0} {h2 : i < n} (s: sstack α n) : α :=
match i, s with
  | 0, ⟨stack.push x s, _⟩ := x
  | i, ⟨stack.push _ s, _⟩ := sget' (pred i) ⟨s, _⟩
  | _, ⟨stack.empty, _⟩    := sorry  -- just ignore this

精益在这两种情况下都会抛出 unknown identifier sget' 错误。我知道我可以从 ehh 模式守卫递归调用 sget'(不确定如何正确调用它们),但是有没有办法用策略 and/or 匹配表达式来做类似的事情?

如果使用等式编译器就可以进行递归调用

def map (f : α → β) : list α → list β
| [] := []
| (a :: l) := f a :: map l

否则你应该使用 induction 策略或显式递归函数之一(如 nat.rec)。