Working with Modules at Toplevel

Hi,

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 "MyModlue.ml";;

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:

MyModule.ml

module MyModlue = struct

(* File contents: E.g. *)

let give_me_some_string = "Hello World"

end

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

Main.ml

let () = print_endline MyModlue.give_me_some_string

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

3 Likes

@octachron, thanks!

This works:

#mod_use "MyModule.ml";; 

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

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