How to use OCaml's [@tailcall] annotation to assert tail-recursiveness?

老子叫甜甜 提交于 2019-12-06 00:35:38

The docs say in subsection 18.1 that

“ocaml.tailcall” or “tailcall” can be applied to function application in order to check that the call is tailcall optimized. If it it not the case, a warning (51) is emitted.

Since your second example does not apply f, the attribute is not applicable in this context.

did you try :

let rec f = function
| 0 -> 0
| x -> (|>) (x - 1) (f[@tailcall])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!