Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml - how to load file.ml

Tags:

file

ocaml

How to load a file myfile.ml that I can use it my file ? And where should I put this file to compilator find it ? I can't do it now. Thanks in advance!

like image 882
user3077133 Avatar asked Dec 17 '13 20:12

user3077133


2 Answers

you can also run utop with the -init option:

utop -init yourfile.ml
like image 131
user6439550 Avatar answered Sep 19 '22 14:09

user6439550


You don't say what kind of system you're using. It's also not clear whether you're trying to load code into the toplevel (the interpreter), use external functions from an OCaml program or something else. It would help if you explained more carefully.

In the meantime, here's a session with a Unix-like system (Mac OS X) that shows how to load a file into the toplevel:

$ cat myfile.ml
let f x = x + 1
$ ocaml
        OCaml version 4.00.1

# #use "myfile.ml";;
val f : int -> int = <fun>
# f 14;;
- : int = 15
#

For this purpose, it doesn't matter too much where your file is. You just need to specify its name in the #use directive. If you don't know how to specify a filename, that's not an OCaml problem--and it's probably the first thing you need to figure out :-)

like image 34
Jeffrey Scofield Avatar answered Sep 22 '22 14:09

Jeffrey Scofield