I'm trying to load my modules in .cmo into the toplevel, I had tried:
$ ocaml mymodule.cmo
I got the toplevel prompt, but I couldn't refer to Mymodule
I also tried the
#load "mymodule.cmo"
It did not complain but still can't refer to Mymodule
I also tried
#use "mymodule.ml"
This seems to work, but it does not load the code into the Mymodule namespace, which is a problem because I actually want to load a few modules into top-level, and they refer to each other by their module namespace.
After you do
#load "mymodule.cmo"
you can refer to your module, but you still need to use the module name:
Mymodule.x
If you want to use a simple name (x
), you also need to open
the module:
open Mymodule
This could be the source of your problem.
Here's a session that shows what I'm talking about:
$ cat mymodule.ml
let x = 14
$ ocaml312
Objective Caml version 3.12.0
# load "mymodule.cmo";;
# x;;
Characters 0-1:
x
^
Error: Unbound value x
# Mymodule.x;;
- : int = 14
# open Mymodule;;
# x;;
- : int = 14
#
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