3

I have a project structured like this :

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.ml : https://pastebin.com/U0h69uRy

dune :

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

When I try dune build, I get this error :

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

Do you know how to fix this ?

Butanium
  • 726
  • 5
  • 19

2 Answers2

2

Got some hint on the ocaml discord.

My problem was that to access to the open_path function, I had to use

Mcts.Readertsp.Readertsp.open_path

Because if I don't add (wrapped false) to the dune mcts file, it puts all libraries in an only module called Mcts. With a dune file like this :

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

I can call my function like this :

Readertsp.Readertsp.open_path

As highlighted by glennsl in the comment, my last mistake is that I was creating a module inside my Readertsp.ml file, which is already a module itself.

After deleting the module Readertsp = struct in my Readertsp.ml file, I can finally call

Readertsp.open_path
Butanium
  • 726
  • 5
  • 19
0

dune will auto-generate a namespace module to prevent collisions between modules with the same name from different libraries. The name of the module will be the library name capitalized. Readertsp should therefore be accessible as Mcts.Readertsp.

Note that you can also override the auto-generated namespace module by providing a similarly named module (Mcts.ml in this case).

glennsl
  • 28,186
  • 12
  • 57
  • 75
  • Hey, with `wrapped = false` I could avoid using `Mcts.` (idk if it's a good practice or not) but not `Readertsp.Readertsp.`, do you know how to deal with that ? – Butanium Nov 17 '21 at 22:23
  • Answered the latter in a comment on your answer. `wrapped = false` is not a good idea I think, as that will increase the likelihood of modules from different libraries conflicting with each other. – glennsl Nov 17 '21 at 22:26
  • do I need to use Mcts.Readertsp if I want to use `Readertsp` in another module of the mcts library ? – Butanium Nov 17 '21 at 22:28
  • No, the namespace module is only needed for consumers of the library. – glennsl Nov 17 '21 at 22:30