Working with Modules at Toplevel



Sorry this seems like a ridiculous question to have to ask but how does one go about loading a module so that it is still contained in it’s own “namespace” (not sure this is the correct term, “submodule”?) when using a REPL such as utop?

Everywhere I look I am seeing the suggestion to do: #use "";;

Which almost does what I am asking but puts everything into the Toplevel and not into its own module. I can make it work using this command by wrapping the file contents in something like:

module MyModlue = struct

(* File contents: E.g. *)

let give_me_some_string = "Hello World"


But then it’s unreadable from another file in the project with something like:

let () = print_endline MyModlue.give_me_some_string


You can use #mod_use "" to load a file as a Module_name module. Note also that the #help directive lists all available toplevel directives.


@octachron, thanks!

This works:

#mod_use "";; 

I’d even tried guessing some but hadn’t tried #mod_use.

Also #help doesn’t work, at least from my utop.