我有两个模块 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
在乌托邦:
#load "a.cmo";;
#use "b.ml";;
关于ocaml - 在 utop 中加载具有依赖关系的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46916099/