ocaml - 在 utop 中加载具有依赖关系的模块

标签 ocaml utop

我有两个模块 A.mlB.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/

相关文章:

ocaml - 接收 Stdlib.Scanf.Scan_failure : character '\\n'

ocaml - OPAM 和 OCaml 安装

module - 如何在 utop 中加载 .ml 文件及其对应的 .mli 文件?

ocaml - 使用 ocaml utop 打印历史列表

ocaml - ocaml中float的绝对值

emacs - 如何在 Emacs 中为 Ocaml 生成和设置注释?

arrays - 我什么时候需要使用 Bigarray,为什么?

operators - 如何修改 OCaml 中的一元运算符?

types - 在 Ocaml 中定义 lambda 表达式的类型

java - 如何通过C函数调用方便OCamljava编译ocaml库?