简体   繁体   中英

Use several modules in OCaml utop

I'm reading an OCaml project recently and I want to put the source files in the utop so I can do some experiments.
Suppose I have two files amodule.ml , bmodule.ml .
bmodule.ml will use functions defined in amodule.ml , for example, bmodule use Amodule.anyfunction() where anyfunction() is defined in amodule.ml .
I want to put both of them in utop:

#directory "/directory contain amodule.ml and bmodule.ml"
#use "amodule.ml"
#use "bmodule.ml"

And this doesn't work because Amodule is a module name base on the amodule.ml file and the utop don't know these things, I think.
So how I can put these files in the utop without changing the file content?

#use a.ml executes every statement in a.ml just as if you had typed those statements in the toplevel directly. Thus, you do not get a module A defined, so your other file cannot have things like A.foo . If you want module A , you must first byte compile a.ml, and then #load a.cmo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM