Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ocaml toplevel module loading

Tags:

load

ocaml

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.

like image 709
romerun Avatar asked Dec 18 '11 18:12

romerun


1 Answers

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
# 
like image 68
Jeffrey Scofield Avatar answered Nov 09 '22 17:11

Jeffrey Scofield