Problem with importing the Unix module in an OCaml script


I’m developing an OCaml script and I’m having trouble importing an external module (in this case, it’s the Unix module, but I have encountered this problem with any module). The problem is as follows: when I open the OCaml console (ocaml from the terminal), the library is successfully imported with the command open Unix;;. However, when I try to import Unix through my script (let’s call it with the command #use "";;, I get stuck. I have tried several things, including: confirming that Unix is installed; exporting the Unix path in ~/.bashrc (on OS X); and trying to use the utop toplevel manager instead of the standard one, but none of these solutions have worked. Has anyone else encountered this issue before? I have attached a reproduction of the problem in the command prompt below.


You haven’t included a log of actual error you got, but in general whenever you wish to use a library in the toplevel, you need to load it first, either by 1) passing it on the command line (ie ocaml unix.cma), or 2) using #load "unix.cma";; from inside the toplevel.