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

3

I have two modules A.ml and B.ml like so:

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

1
{btsdaf} - gsg
1个回答

5

首先,您需要编译 a.ml 文件:

  ocamlc -c a.ml  // yields a.cmo

在UTOP中:

  #load "a.cmo";;
  #use "b.ml";;

我明白了。甚至可以将这些命令放入init.ml中,并使用utop -init init.ml,这样每次启动utop时就不必再调用这些命令了。谢谢! - gallais

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接