I have a script which runs perfectly as a script (i.e.,
ocaml myscript.ml). But I wanted to use OCaml interactively (i.e.,
ocaml followed by
#use "./myscript.ml") to remind myself of the types that it infers, and when I did that, I got error messages which indicated that ocaml was assuming I am using the Base module.
I have traced this to the fact that
ocaml loads an initialization file (./.ocamlinit or $XDG_CONFIG_HOME/ocaml/init.ml or $HOME/.ocamlinit) (one of these in fact contains
open Base), but
ocaml myscript.ml does not. So I can fix the interactive case by giving the command
But why does
ocaml load the initialization file only when no script argument is given? According to
man ocaml, it seems that it should try to load an init file unless
-noinit is given.
Ocaml version 4.14.