ocamlmerlin

(Ocaml) unbound module error on visual code


I have just started to learn Ocaml. I'm using visual code as my IDE on Ubuntu, and I have OCaml extension and merlin installed.

and I have the following problem -

my workspace folder contains only 2 files: a.ml and b.ml.

In the file a.ml I have defined a module named "COOL", and in the file b.ml I wrote:

~ b.ml ~

open COOL;;

I get an error that says "Unbound module COOL merlin"

Is there any way to make it see the module on file a.ml? I tried searching for solution, I saw something with makefile and .merlin and B build but I didn't understand it, I don't have anything but the 2 files I mentioned. I would be happy if someone can tell me what exactly should be done in order for this little example to work.


Solution

  • tl; dr: do ocamlc -c a.ml (or whatever your compilation command is) in order to generate the a.cmi file that merlin will use to get the list of symbols defined in module A.

    Apart the fact that in b.ml your module is indeed named A.COOL (unless you open A before open COOL) as mentioned by glennsl, the point is that merlin is, as far as I know, only watching the current file being edited, i.e. b.ml in your case. In order to have access to external symbols, you thus need to have compiled the other files (or at least their corresponding .mli if they exist), in order to have the relevant .cmi files available to merlin.

    This is implicit in the paragraph of the documentation describing build paths, which says "[merlin] needs to know where to find the cmi files of the other modules of your project", i.e. those files need to exist in the first place.