OCaml 顶层多重依赖

cho*_*ger 5 ocaml

当我有多个依赖项时,比如说

module A = struct
  open B
  ...
  end

module B = struct
  ...
  end
Run Code Online (Sandbox Code Playgroud)

是否可以让 OCaml toplevel/utop 加载具有所有依赖项的 A.ml(即#use "./A.ml"自动加载 B.ml)?

Tho*_*ash 3

您应该使用 ocamlc 编译所有模块以生成文件a.cmob.cmo然后运行ocaml b.cmo a.cmo(顺序很重要,因为B必须在之前加载A)。