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?
In short, the toplevel is OCaml's Read-Eval-Print-Loop (repl) allowing interative use of the OCaml system. You can consider the toplevel an alternative to compiling OCaml into an executable.
In a terminal window, type utop to start the interactive OCaml session, commonly called the toplevel. Press Control-D to exit the toplevel. You can also enter #quit;; and press return. Note that you must type the # there: it is in addition to the # prompt you already see.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With