我正在按照教程http://caml.inria.fr/pub/docs/oreilly-book/html/index.html学习OCaml。我想尝试使用'core'库的list函数的一些例子。 我启动ocaml-top(http://www.typerex.org/ocaml-top.html)并在打开'Core.Std'时出现以下错误:
# open Core.Std
Characters 0-13:
open Core.Std;;
^^^^^^^^^^^^^
Error: Unbound module Core
文件〜/ .ocamlinit包含以下行(从Ocaml and Opam: unbound module Core添加):
(* Added by OPAM. *)
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;
#use "topfind"
#camlp4o
#thread
#require "core"
#require "core.top"
#require "core.syntax"
从命令行执行ocaml工作正常(它在init上加载了很多.cma文件)并且打开'Core.Std'没有问题。 我可以用以下代码编译模块:
$ ocamlfind ocamlc -thread -package core calc.ml
我创建了自己的“核心”链接,并且工作正常:
$ ocamlfind ocamlmktop -o coretop -thread -package core
但ocaml-top无法打开'Core.Std'。使用我的顶层启动ocaml-top不会打开'Core.Std'
$ ocaml-top -ocaml /home/thelinuxkitten/coretop
在ocaml-top的提示符下插入〜/ .ocamlinit的内容
(* Added by OPAM. *)
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;
#use "topfind";;
#camlp4o;;
#thread;;
#require "core";;
#require "core.top";;
#require "core.syntax";;
在评估面板中生成以下输出:
OCaml version 4.01.0
# let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
# #use "topfind"
- : unit = ()
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
Topfind.reset();; to force that packages will be reloaded
#thread;; to enable threads
- : unit = ()
# #camlp4o
Camlp4 Parsing version 4.01.0
# #thread
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/dynlink.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/camlp4: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/camlp4/camlp4o.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/threads: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/unix.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/threads/threads.cma: loaded
# #require "core"
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/bigarray.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/bin_prot: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/bin_prot/bin_prot.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/variantslib: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/variantslib/variantslib.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/sexplib: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/sexplib/sexplib.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/fieldslib: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/fieldslib/fieldslib.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_bench: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_bench/pa_bench_lib.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/oUnit: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/oUnit/oUnitAdvanced.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/oUnit/oUnit.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_ounit: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_ounit/pa_ounit_lib.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/typerep_kernel: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/typerep_kernel/typerep_kernel.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core_kernel: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core_kernel/raise_without_backtrace.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core_kernel/core_kernel.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_test: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_test/pa_test.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core/core.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core/core_top.cma: loaded
# #require "core.top"
# #require "core.syntax"
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/core/core_top.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/type_conv: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/type_conv/pa_type_conv.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/sexplib/pa_sexp_conv.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/fieldslib/pa_fields_conv.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/variantslib/pa_variants_conv.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/comparelib: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/comparelib/comparelib.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/comparelib/pa_compare.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/bin_prot/pa_bin_prot.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/custom_printf: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/custom_printf/pa_custom_printf.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_pipebang: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/pa_pipebang/pa_pipebang.cma: loaded
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/herelib: added to search path
/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/herelib/pa_herelib.cma: loaded
#
我已经使用OPAM安装了OCaml,core和ocaml-top
$ opam config env
CAML_LD_LIBRARY_PATH="/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/stublibs:/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/lib/ocaml/stublibs"; export CAML_LD_LIBRARY_PATH;
OPAMROOT="/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam"; export OPAMROOT;
PERL5LIB="/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/perl5:"; export PERL5LIB;
OCAML_TOPLEVEL_PATH="/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/lib/toplevel"; export OCAML_TOPLEVEL_PATH;
MANPATH="/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/man:/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/man:/usr/local/man:/usr/brlcad/share/man"; export MANPATH;
PATH="/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/.opam/system/bin:/home/thelinuxkitten/ocamlbrew/ocaml-4.01.0/bin:/home/thelinuxkitten/debian/script:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/brlcad/bin"; export PATH;
ocaml-top的网站有一个最简单的文档。 所以,我的问题是:任何人都知道ocaml-top是否可以加载和打开像'core'这样的外部库?
由于
答案 0 :(得分:1)
注意.ocamlinit
在发出其他指令之前#use "topfind"
如何topfind
。那是因为#require
是一个ocaml脚本,它增加了对{{1}}指令的支持。
答案 1 :(得分:1)
按照ygrek的推荐,我在ocaml-top的提示符下输入.ocamlinit的内容,然后评估'open Core.Std ;;'作品。似乎就像Ashish Agarwal所说的那样,ocaml-top不会读取.ocamlinit。
ocaml-top可以加载/打开外部库,但集成的ocaml解释器的初始化必须手动完成。
由于
答案 2 :(得分:1)
首先,请确保您的.profile
或.bashrc
包含以下内容:
eval `opam config env`
然后打开文件~/.opam/system/share/ocaml-top/toplevel_init.ml
。该文件在启动时由ocaml-top读取。插入以下行:
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;
#use "topfind"
#thread
#require "core"
#require "core.top"
#require "core.syntax"