Ocaml 在utop中加载具有依赖项的模块
我有两个模块Ocaml 在utop中加载具有依赖项的模块,ocaml,utop,Ocaml,Utop,我有两个模块A.ml和B.ml,如下所示: A.ml: type t = int let from_int (i : int) : t = i open A let my_t : t = from_int 0 B.ml: type t = int let from_int (i : int) : t = i open A let my_t : t = from_int 0 通过调用ocamlca.mlb.ml我可以很好地编译它们,但是我不知道如何在utop中加载它们,以便交互使用my\t
A.ml
和B.ml
,如下所示:
A.ml
:
type t = int
let from_int (i : int) : t = i
open A
let my_t : t = from_int 0
B.ml
:
type t = int
let from_int (i : int) : t = i
open A
let my_t : t = from_int 0
通过调用ocamlca.mlb.ml
我可以很好地编译它们,但是我不知道如何在utop
中加载它们,以便交互使用my\t
。使用:
产生utop-init B.ml
错误:引用未定义的全局“A”
后跟utop
和#使用A.ml
使用“B.ml”代码>会导致相同的错误
- 从
中删除B.ml
会使这个doubleopena
工作,但是#use
现在在ocamlc A.ml B.ml
上失败,出现B
错误:未绑定类型构造函数t
ocamlc -c a.ml // yields a.cmo
在utop中:
#load "a.cmo";;
#use "b.ml";;
我懂了。甚至可以将它们放入
init.ml
并使用utop-init init.ml
,这样就不必在每次启动utop
时调用这些命令。谢谢#use
用于直接包含-要将文件作为模块转储到顶层,您需要#mod#u use
。还有ocamlmktop,它构造了一个顶层,其中链接了一组模块。最后是Pierre的回答中给出的加载。