如何使两个方法互相调用? [英] How to have two methods calling each other?
本文介绍了如何使两个方法互相调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于如何让两个方法互相调用(即让A()
调用B()
和B()
调用A()
),我有些困惑.似乎F#仅在代码中遇到后才看到"该方法,因此,如果没有,它只会说 value或未定义构造函数.
我在这里错过了一些非常基本的东西吗?
解决方案
'let rec ... and ...'是您要寻找的语法.
let rec F() =
G()
and G() =
F()
另请参阅 F#Co中的冒险-递归.
I'm a bit confused as to how to get two method to call each other (i.e., have A()
call B()
and B()
call A()
). It seems that F# only 'sees' the method after it's been encountered in code, so if it hasn't, it just says value or constructor has not been defined.
Am I missing something very basic here?
解决方案
'let rec... and...' is the syntax you seek.
let rec F() =
G()
and G() =
F()
See also Adventures in F# Co-Recursion.
这篇关于如何使两个方法互相调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文