无法在Ocaml TopLevel中使用FindLib加载电池

时间:2013-02-19 00:12:57

标签: functional-programming ocaml ocaml-batteries

我成功安装了ocaml-batteries-includedfindlib

我可以毫无问题地做'ocamlfind ocamlc -package batteries -c mycode.ml`。

另外,如果我ocamlfind list,我会

$ ocamlfind list
batteries           (version: 2.0)
batteries.pa_comprehension (version: 2.0)
batteries.pa_comprehension.syntax (version: 2.0)
batteries.pa_llist  (version: 2.0)
batteries.pa_llist.syntax (version: 2.0)
batteries.pa_string (version: 2.0)
batteries.pa_string.syntax (version: 2.0)
batteries.syntax    (version: 2.0)
bigarray            (version: [distributed with Ocaml])
camlp4              (version: [distributed with Ocaml])
...

using batteries中的问题是ocaml (toplevel)

我按照说明设置了.ocamlinit

#use "topfind";;

Toploop.use_silently
             Format.err_formatter (Filename.concat (Findlib.package_directory
             "batteries") "battop.ml");;

但是当我启动ocaml时,我明白了:

$ ocaml
        OCaml version 4.00.1

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

Exception: Fl_package_base.No_such_package ("batteries", "").

此外,如果我在#listocaml toplevel,我会

# #list;;
bigarray            (version: [distributed with Ocaml])
camlp4              (version: [distributed with Ocaml])
camlp4.exceptiontracer (version: [distributed with Ocaml])
camlp4.extend       (version: [distributed with Ocaml])
...

我看不到batteries包。


有什么问题?

1 个答案:

答案 0 :(得分:4)

你有没有使用OPAM的原因? (https://github.com/OCamlPro/opam

安装OPAM,切换到您喜欢的4.0x版本编译器(例如opam switch 4.00.1),然后运行:opam install batteries。我建议使用opam install utop并使用utop代替vanilla顶级。在任何一种情况下:

将以下内容放入~/.ocamlinit

#use "topfind";;
#require "batteries";;
open Batteries;;

这就是让电池工作所需的一切。