将一个 ml 文件导入另一个文件

importing one ml file into another

我有一个 interpreter.ml 文件,其中包含一个解释器和一些 type 定义。

我开发了一些测试电池来检查解释器是否正常工作。

当我将用于测试解释器行为的函数放在解释器的同一个文件中时,一切正常,但如果我尝试使用不同的文件进行测试(假设 tests.ml ) 它没有加载解释器函数和定义。

interpreter.mltests.ml 在同一个文件夹中

我从 tests.ml 内部尝试了 open Interpreter#use "./interpreter.ml" 但它不会编译也不会关闭 IDE 中的警告(有点......我我在 MacOs 上使用 Visual Studio 代码)

我已经尝试遵循 official documentation 但它不会与 ocamlopt -c tests.ml

一起编译

作为讨论的结果,可执行文件是通过以正确的顺序编译 2 个文件 test.ml & interpreter.ml 获得的(test.ml 依赖于 [=13= 中定义的对象]; 因此 test.ml 必须通过子句 open Interpreter 或通过在所有相关项目前加上前缀 Interpreter 来引用解释器对象:

 ocamlc -o exec interpreter.ml test.ml

ocamlbuild 更容易,因为它自己解决了依赖关系: 以下命令:

 ocamlbuild test.native 

将生成可执行文件。