为什么通用函数模板不能使用 fnx 来确保它们是 tail-recursive?

Why can't generic function templates use fnx to ensure they are tail-recursive?

真的只是标题。

正在编译

fnx {a:t@ype} repeat {n:nat} .<n>.
( x: a
, t: int n
, f: a -> a
) : a =
  if t = 0 then x
  else repeat (f x, t - 1, f)

给予

warning(2): [fnx] is treated as [fun] for initiating function templates!

我是否应该相信我没有搞砸定义并不小心创建了一个 non-tail-recursive 函数?有没有一些标准的方法来规避这个?

注意'fnx'只对定义相互递归函数有意义

在你的例子中,使用 'fun' 就好了:编译器可以识别尾递归 调用 'repeat' 的主体并将其变成本地跳转。