【问题标题】:Error: Unbound module Core when attempting to open Core module with utop from command line错误:尝试从命令行使用 utop 打开核心模块时未绑定模块核心
【发布时间】:2014-06-06 22:20:35
【问题描述】:

我正在尝试通过设置 opamutop 以及核心模块来跟随 Real World OCaml。 I've followed these directions 取得了一些成功。特别是,当我运行 utop 而不指定要加载的文件时,我可以毫无问题地加载 Core:

[dswain@Dupree scratch]$ utop
Welcome to utop version 1.12 (using OCaml version 4.01.0)!                                                                                    

Findlib has been successfully loaded. Additional directives:
...

utop # open Core;;
utop # 

到目前为止一切顺利。现在,如果我尝试使用相同的代码从命令行加载脚本:

[dswain@Dupree scratch]$ cat test.ml 
open Core.Std;;
[dswain@Dupree scratch]$ utop test.ml 
File "test.ml", line 1, characters 0-13:
Error: Unbound module Core
[dswain@Dupree scratch]$ 

我认为这是我在某处犯的配置错误,但我不太确定在哪里。

设置详情

我尝试重新安装 ocamlopamutopcore 均无济于事。我知道opam init 在设置过程中进行了以下配置更改:

~/.ocamlinit:

#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
#require "core.syntax";;

~/.bash_profile

# OPAM configuration
. /home/dswain/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

eval `opam config env`

我正在运行 Arch Linux,并按照步骤通过 AUR 安装 opam,没有发现任何问题。我还能够根据安装说明构建和安装所有软件包,而没有任何我知道的错误。

【问题讨论】:

    标签: ocaml opam utop


    【解决方案1】:

    这是因为 utop 在运行 .ocamlinit 文件之前会执行一个脚本文件。我不确定它是错误还是功能,但这就是代码的编写方式。事实上,大多数用户从 emacs 运行 utop,并使用 C-c C-s 将代码片段发送到 utop。

    如果您对 emacs 不满意,我可以建议使用以下工作流程:

    1. 从头开始
    2. 在您喜欢的编辑器中编写代码
    3. 使用#use "your_file.ml";;在utop中加载代码
    4. 玩一下,如果不满意,请转到2

    【讨论】:

    • 我确实使用 emacs,所以这对我来说不是什么大问题(不是说我很擅长,但我确实使用它)。我对它进行了更多研究,我还用corebuild 编译了这个例子,看看这是否会有所作为。虽然我没有得到完全相同的错误,但在尝试执行未在 Float 模块(我认为来自 Core.Std)上定义的函数时确实遇到了错误。
    • 我想,您使用 Float 模块得到的错误是真实的,不是由配置问题引起的。
    • 我将此标记为答案,因为似乎尝试通过 emacs 运行 utop 绝对是完成这项工作的最简单方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    • 2014-10-12
    相关资源
    最近更新 更多