什么是生成.tail IL指令的简单F#代码?

kld*_*010 7 .net f# tail-recursion tail-call-optimization

我想看看.tailIL指令,但是我使用尾调用的简单递归函数显然已优化为循环.我实际上正在猜测这个,因为我不完全确定Reflector中的循环是什么样的.我绝对没有看到任何.tail操作码.我在项目的属性中检查了"生成尾调用".我也在Reflector中尝试了Debug和Release版本.

我使用的代码来自Chris Smith的Programming F#,第190页:

let factorial x =
// Keep track of both x and an accumulator value (acc)
let rec tailRecursiveFactorial x acc =
    if x <= 1 then
        acc
    else
        tailRecursiveFactorial (x - 1) (acc * x)
tailRecursiveFactorial x 1
Run Code Online (Sandbox Code Playgroud)

任何人都可以建议一些简单的F#代码,它们确实会生成.tail

Bri*_*ian 6

相互递归函数应该:

let rec even n = 
    if n = 0 then 
        true 
    else
        odd (n-1)
and odd n =
    if n = 1 then 
        true 
    else
        even (n-1)
Run Code Online (Sandbox Code Playgroud)

(刚才没试过).

编辑

也可以看看

我怎么知道函数是否在F#中是尾递归的