0

我有一个结构如下的项目:

root/
|—— dune-project
|—— lib/
|  |—— dune
|  |—— Readertsp.ml
|  |-- ...
|
|—— bin/
|  |—— dune
|  |—— bin.ml

bin.ml

let city_config = "ch130" in
let path = Readertsp.open_path city_config in ();;

dune

(executable
 (name MCTS_main)
 (libraries graphics mcts)
)

Readertsp.mlhttps ://pastebin.com/U0h69uRy

dune

(library
 (name mcts)
 (modules Readertsp)
 (libraries graphics))

当我尝试沙丘构建时,我收到此错误:

File "tests/MCTS_main.ml", line 3, characters 0-19:
3 | Readertsp.open_path city_config;;
    ^^^^^^^^^^^^^^^^^^^
Error: Unbound module Readertsp

你知道如何解决这个问题吗?

4

2 回答 2

0

dune将自动生成命名空间模块,以防止来自不同库的同名模块之间发生冲突。模块的名称将是大写的库名称。Readertsp因此应该可以作为Mcts.Readertsp.

请注意,您还可以通过提供类似命名的模块(Mcts.ml在本例中)来覆盖自动生成的命名空间模块。

于 2021-11-17T22:20:32.100 回答
0

得到了关于 ocaml 不和谐的一些提示。

我的问题是要访问 open_path 函数,我必须使用

Mcts.Readertsp.Readertsp.open_path

因为如果我不添加(wrapped false)到沙丘 mcts 文件中,它会将所有库放在一个名为Mcts. 使用这样的沙丘文件:

(library
 (wrapped false)
 (name mcts)
 (modules Readertsp)
 (libraries graphics))

我可以这样调用我的函数:

Readertsp.Readertsp.open_path

正如 glennsl 在评论中强调的那样,我的最后一个错误是我在我的Readertsp.ml文件中创建了一个模块,它本身已经是一个模块。

module Readertsp = struct在我的文件中删除后Readertsp.ml,我终于可以打电话了

Readertsp.open_path
于 2021-11-17T22:21:23.883 回答