How can I load a ml file in toplevel of OCaml, just like `use mine.sml` in SML/NJ?
13,907
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.
Related videos on Youtube
Author by
Jackson Tale
OCaml Driver for MongoDB OCaml encoder/decoder for BSON Many things about OCaml
Updated on June 06, 2022Comments
-
Jackson Tale almost 2 years
In
SML
'srepl
, you can just typeuse whatever.sml
and load all things inside that.sml
intorepl
.How can I do that in OCaml?
-
Alexander Mills over 5 yearsfml, why are there so many REPL questions? I want to load an .ml file from another in an actual program not the f'ing REPL lol. I don't understand why people even use a REPL...please educate me.
-
-
gasche about 11 yearsNote that the
#
of#use
must really be typed by the user as an additional character, this is not a reference to the beginning prompt. The whole line will therefore look like# #use "file.ml";;
. Users are frequently confused about this. -
pad about 11 years@gasche: Thanks, I added your example for clarification.