Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 872
Jackson Tale Avatar asked Feb 07 '13 16:02

Jackson Tale


People also ask

What is OCaml toplevel?

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.

How do I get out of toplevel OCaml?

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.


1 Answers

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.

like image 95
pad Avatar answered Oct 28 '22 21:10

pad