Dependency problem with dune

Hi!

I have a problem with dune which probably has a very simple solution, but I haven’t been able to figure it out. My current directory setup for defining a simple library looks like this:

lib/ 
|--- dune
|--- lib.ml 
|--- transform.ml

File lib.ml basically just includes a definition of a type t and some pretty printing function for it. Now I would like to include a function f that can take a value of type t and transform it into another value of type t. Since this is logically independent of the definition of t itself I would like for it to go into it’s own module inside the library, so I put it into transform.ml. When I try to build this with dune I get:

Error: Module Transform in directory _build/default/lib depends on Lib.
This doesn't make sense to me.

Lib is the main module of the library and is the only module exposed
outside of the library. Consequently, it should be the one depending on all
the other modules in the library.

I could put the definition of type t into a file with a different name, but I would actually like for it to be available outside the library as Lib.t. Is there something I’m missing here?

Thanks for any input :slight_smile:

When a module shares the same name as the library name, dune considers that you want to write the entry point of the library yourself in order to control finely which modules are exported by the library.

Such an entry point should only re-export existing definitions. For instance, you can define your type t in another module, and then re-export it with

(* lib.ml *)
type t = Other_module.t

However, if you don’t need to control precisely the modules exported by your library, it is probably simpler to let dune handle the namespacing of modules by not having a lib.ml file.

1 Like