gpt4 book ai didi

function - OCaml:在定义函数之前声明它

转载 作者:行者123 更新时间:2023-12-02 10:30:41 24 4
gpt4 key购买 nike

有没有办法在 OCaml 中定义函数之前声明它?我正在使用 OCaml 解释器。

我有两个功能:

let myFunctionA = 
(* some stuff here..... *) myFunctionB (*some stuff *)

let myFunctionB =
(* some stuff here .... *) myFunctionA (* some stuff *)

但这不起作用,因为 myFunctionA 在创建之前无法调用 myFunctionB。

我已经进行了一些谷歌搜索,但似乎找不到任何东西。我怎样才能做到这一点?

最佳答案

您想要的是使这两个函数相互递归。您必须使用“let ... and ...”,而不是使用“let ... let ...”,如下所示:

let rec myFunctionA = 
(* some stuff here..... *) myFunctionB (*some stuff *)

and myFunctionB =
(* some stuff here .... *) myFunctionA (* some stuff *)

关于function - OCaml:在定义函数之前声明它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7613560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com