我有一个结构如下的项目:
root/
|—— dune-project
|—— lib/
| |—— dune
| |—— Readertsp.ml
| |-- ...
|
|—— bin/
| |—— dune
| |—— bin.mlbin.ml:
let city_config = "ch130" in
let path = Readertsp.open_path city_config in ();;dune
(executable
(name MCTS_main)
(libraries graphics mcts)
)Readertsp.ml:https://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你知道怎么解决这个问题吗?
发布于 2021-11-17 22:20:32
dune将自动生成命名空间模块,以防止不同库中具有相同名称的模块之间发生冲突。模块的名称将是大写的库名称。因此,应该可以作为Mcts.Readertsp访问Readertsp。
请注意,您还可以通过提供一个命名类似的模块(在本例中为Mcts.ml)来覆盖自动生成的名称空间模块。
发布于 2021-11-17 22:21:24
得到了一些关于奥卡姆不和谐的线索。
我的问题是,要访问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文件中创建了一个模块,该文件本身就是一个模块。
在删除Readertsp.ml文件中的module Readertsp = struct之后,我终于可以调用
Readertsp.open_pathhttps://stackoverflow.com/questions/70012130
复制相似问题