简体   繁体   中英

Error: Unbound module Core when attempting to open Core module with utop from command line

I am trying to follow along with Real World OCaml by setting up opam , utop , and the Core modules as well. I've followed these directions with some success. In particular, when I run utop without specifying the file to load, I can load Core with no issues:

[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 # 

So far so good. Now if I attempt to load a script from the command line with the same code:

[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]$ 

I assume this is a configuration mistake I've made somewhere, but I'm not quite sure where.

Setup details

I've attempted to reinstall ocaml , opam , utop , and core to no avail. I've got the following config changes that I'm aware that opam init made during setup:

~/.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`

I'm running Arch Linux, and followed the steps to install opam via the AUR with no issues I'm aware of. I was also able to build & install all of the packages from the installation instructions without any errors I know of.

This is because utop executes a script-file before it runs .ocamlinit file. I'm not sure whether it is a bug or a feature, but that is how the code is written. Indeed, most users runs utop from emacs and send pieces of code to utop with Cc Cs .

If you're not comfortable with emacs, I can suggest to use the following workflow:

  1. start utop
  2. do some coding in your favorite editor
  3. load code in utop with #use "your_file.ml";;
  4. play with it, if not satisfied goto 2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM