How can I load a ml file in toplevel of OCaml, just like `use mine.sml` in SML/NJ?

Jackson Tale picture Jackson Tale · Feb 7, 2013 · Viewed 13.2k times · Source

In SML's repl, you can just type use whatever.sml and load all things inside that .sml into repl.

How can I do that in OCaml?

Answer

pad picture pad · Feb 7, 2013

You have #use directive for that purpose:

#use "file-name";;

Read, compile and execute source phrases from the given file. This is textual inclusion: phrases are processed just as if they were typed on standard input. The reading of the file stops at the first error encountered.

For example (as per @gasche's suggestion):

# #use "whatever.ml";;

Here is a complete list of OCaml directives.