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
    中删除
    opena
    会使这个double
    #use
    工作,但是
    ocamlc A.ml B.ml
    现在在
    B
    上失败,出现
    错误:未绑定类型构造函数t

您必须首先编译a.ml:

  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的回答中给出的加载。