我在 F# 中定义了这两个函数
let f t =
match t with
|_ when t = 0 -> 1
|_ -> g t-1
let g t = 1 + (f t)
但是,F# 编译器不接受它。据说是这样的
stdin(9,16): error FS0039: The value or constructor 'f' is not defined
请帮助我!谢谢。
最佳答案
F# 使用 let rec ... and ...
语法支持相互递归。这是你的例子
let rec f t =
match t with
|_ when t = 0 -> 1
|_ -> g t-1
and g t = 1 + (f t)
关于function - 如何在 F# 中定义相互依赖的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18570702/