什么是一些简单的F#code产生的.tail IL指令? [英] What's some simple F# code that generates the .tail IL instruction?

查看:96
本文介绍了什么是一些简单的F#code产生的.tail IL指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看到的 .tail IL指令,但使用尾简单的递归函数调用,我一直在写,显然是优化成循环。实际上,我猜这一点,因为我不完全知道什么是循环看起来像反射。我绝对看不到任何 .tail 运算codeS虽然。我已经生成尾调用在我的项目的属性进行检查。我也试着调试和发布版本的反射器。

I'd like to see the .tail IL instruction, but the simple recursive functions using tail calls that I've been writing are apparently optimized into loops. I'm actually guessing on this, as I'm not entirely sure what a loop looks like in Reflector. I definitely don't see any .tail opcodes though. I have "Generate tail calls" checked in my project's properties. I've also tried both Debug and Release builds in Reflector.

在code我用的是从编程F#由克里斯·史密斯,页190:

The code I used is from Programming F# by Chris Smith, page 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

任何人都可以提出一些简单的F#code这的确会产生 .tail

推荐答案

相互递归函数应该:

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)

(还没有尝试过刚才)。

(have not tried it just now).

修改

另请参见

<一个href="http://stackoverflow.com/questions/806712/how-do-i-know-if-a-function-is-tail-recursive-in-f">http://stackoverflow.com/questions/806712/how-do-i-know-if-a-function-is-tail-recursive-in-f

这篇关于什么是一些简单的F#code产生的.tail IL指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆