在 utop 中加载具有依赖关系的模块
Loading a module with dependencies in utop
我有两个模块 A.ml
和 B.ml
像这样:
A.ml
:
type t = int
let from_int (i : int) : t = i
B.ml
:
open A
let my_t : t = from_int 0
我可以通过调用 ocamlc A.ml B.ml
来编译它们,但是我不知道如何在 utop
中加载它们以便交互使用 my_t
。使用:
utop -init B.ml
产量 Error: Reference to undefined global 'A'
utop
后跟 #use "A.ml";;
和 #use "B.ml";;
导致相同的错误
- 从
B.ml
中删除 open A
使这个双 #use
工作但是 ocamlc A.ml B.ml
现在在 B
上失败 Error: Unbound type constructor t
.
你必须先编译 a.ml :
ocamlc -c a.ml // yields a.cmo
在 utop 中:
#load "a.cmo";;
#use "b.ml";;
我有两个模块 A.ml
和 B.ml
像这样:
A.ml
:
type t = int
let from_int (i : int) : t = i
B.ml
:
open A
let my_t : t = from_int 0
我可以通过调用 ocamlc A.ml B.ml
来编译它们,但是我不知道如何在 utop
中加载它们以便交互使用 my_t
。使用:
utop -init B.ml
产量Error: Reference to undefined global 'A'
utop
后跟#use "A.ml";;
和#use "B.ml";;
导致相同的错误- 从
B.ml
中删除open A
使这个双#use
工作但是ocamlc A.ml B.ml
现在在B
上失败Error: Unbound type constructor t
.
你必须先编译 a.ml :
ocamlc -c a.ml // yields a.cmo
在 utop 中:
#load "a.cmo";;
#use "b.ml";;