Ocaml 中函数之间的循环依赖

Circular dependencies between functions in Ocaml

我在ocaml中看到了一些关于循环依赖的问题,但它们都是关于类型之间的依赖。

在我的例子中,我有一个名为 eval 的函数。它模拟了一种编造语言的解释器,需要调用这样的函数:

let rec eval e r = 
match e with
(* ... *)
    Forall(p, s) ->
        let pred = eval p r in
            let set = eval s r in
                forall pred s |
(* ... *)

问题是,forall 看起来像这样:

let forAll (p : exp) (s : evT) : evT =
    match s with
    SetVal(Empty(_)) -> (Bool true) |
    SetVal(Set(lst, _)) ->
        match p with
                   (* irrelevant code *)
                        match l with
                            [] -> acc |
                            h::t -> aux t ((eval (FunCall(p, (evTToExp h))) env0)::acc)
                in
                    (* irrelevant code *)

如您所见,它都需要调用和调用 eval.

如果我将 eval 的定义放在我的 .ml 文件的第一位,我会得到 Unbound value forall,否则我会得到 Unbound value eval.

如何解决这种依赖?我如何让 ocaml 知道它 在文件的其他地方找到缺失函数的定义?

相互递归是通过recand关键字实现的:

let rec eval = ...

and forAll = ...