F#:相互递归函数
可能的重复:
[F#] 如何让两个方法相互调用?
大家好,
我有一个场景,我有两个函数可以从相互递归中受益,但我不太确定如何在 F# 中执行此操作
我的场景并不像下面的代码那么简单,但我想得到类似于编译的东西:
let rec f x =
if x>0 then
g (x-1)
else
x
let rec g x =
if x>0 then
f (x-1)
else
x
Possible Duplicate:
[F#] How to have two methods calling each other?
Hello all,
I Have a scenario where I have two functions that would benefit from being mutually recursive but I'm not really sure how to do this in F#
My scenario is not as simple as the following code, but I'd like to get something similar to compile:
let rec f x =
if x>0 then
g (x-1)
else
x
let rec g x =
if x>0 then
f (x-1)
else
x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用
let
rec
...and
形式:You can also use
let
rec
...and
form:要获得相互递归函数,只需将一个函数作为参数传递给另一个函数
To get mutually recursive functions simply pass one to the other as a parameter
使用
let rec ... and ...
构造:Use the
let rec ... and ...
construct: