Interface problems when OCaml is installed without opam

In my last hands-on with students (first course about OCaml), I was dealing with modules and interface files. The ones who had installed OCaml on their computers (not the schools’) couldn’t apparently load modules from other files (in the same directory). I can’t remember the specific error message (it was a couple of weeks ago), but it was along the lines of “module not found”.
I asked and they had not used opam to install OCaml (they hadn’t much time with OCaml actually).

I was wondering: does this problem occur because they hadn’t used opam? If so, is there a way to circumvent this when installation has not been properly conducted?

I would actually be interested in knowing other bugs that can happen when opam is not used.

Just trying to guess here, but to me it looks like the student’s installation was simply too old and some modules from the standard library are missing (e.g. Float, Result do not exist in OCaml < 4.08)

It sounds unlikely to me if you’re only using the standard library. If you’re using external libraries, there shouldn’t be any issues as long as you use build-systems/tools such as dune or ocamlfind as the old way of loading external libraries (e.g. -I +this-external-pkg & expkg.cma on linking) is very brittle.

Depending on how you build the project, you could add a prior check such as testing if the output of ocaml -version >= 4.08

1 Like

They were actually trying to load modules that they had just defined in the same directory.
We checked their ocaml versions, and they were up-to-date. We were two teachers in the room, we also checked the name of their files and modules and that they were in the same directory, but we couldn’t explain the bug.

A possible issue is that between OCaml 4.09.0 and 4.12.1(included), the toplevel cached directory contents during startup, so files created after the toplevel startup could not be loaded without re-adding the corresponding directory to the path. This confusing behavior is fixed in OCaml 4.13.0 .


This is interesting. But, if I remember correctly (once again, I’m sorry I didn’t write earlier), we also tried to restart the top-level and that didn’t work.

Really depends on the exact command that was run. For example, if you are compiling a module M1 which refers to another M2, then M2 needs to be in the same compilation unit and available before M1. Otherwise you get ‘module not found’.

For reasons like this (and many others) it’s best to only support standardized OCaml tooling like opam and dune for package and build management.

Well, we also checked that. That’s why I was wondering if it could be related to the way they installed OCaml. Next year, they will probably use opam anyway, but I was curious

At the same time, neither opam nor dune have any kind of built-in support in the lower level tools like the compiler. Thus differences in behavior of the ocaml REPL should be a matter of difference of OCaml version and/or different shell or REPL history.