我的rec函数尾部递归吗? [英] Is my rec function tail recursive?

查看:100
本文介绍了我的rec函数尾部递归吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这个函数是尾递归的吗?


Is this function tail-recursive ?

let rec rec_algo1 step J = 
    if step = dSs then J
    else
        let a = Array.init (Array2D.length1 M) (fun i -> minby1J i M J)
        let argmin = a|> Array.minBy snd |> fst
        rec_algo1 (step+1) (argmin::J)

通常,有没有办法正式对其进行检查?

In general, is there a way to formally check it ?

谢谢.

推荐答案

此函数是尾递归的;我可以通过目光辨别出来.

This function is tail-recursive; I can tell by eyeballing it.

通常来说,并非总是那么容易分辨.也许最可靠/最实用的方法是仅在较大的输入上对其进行检查(并确保您在发布"模式下进行编译,因为调试"模式会关闭尾部调用以进行更好的调试).

In general it is not always easy to tell. Perhaps the most reliable/pragmatic thing is just to check it on a large input (and make sure you are compiling in 'Release' mode, as 'Debug' mode turns off tail calls for better debugging).

这篇关于我的rec函数尾部递归吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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