如何使用Jane Street的Core在Reason中?

7

我是OCaml的新手,正在尝试使用Facebook Reason语法。我无法找到一种方法来编译它,因为它找不到Core模块(已经通过opam安装)。

我正在尝试从《实用OCaml》中编译一个示例程序。

open Core.Std;

let rec read_and_accumulate accum => {
  let line = In_channel.input_line In_channel.stdin;
  switch line {
    | None => accum
    | Some x => read_and_accumulate (accum +. Float.of_string x)
  }
};

let () = printf "Total: %F\n" (read_and_accumulate 0.);

这是我用于编译的命令:rebuild accum.native
当我在_tags中加入以下内容时(按照https://janestreet.github.io/installation.html上的说明):
true: package(core,ppx_jane)
true: thread,debug

我的错误消息一直在变但我仍然不知道该怎么办:

File "_tags", line 1, characters 6-28:
Warning: tag "package" does not expect a parameter, but is used with parameter "core,ppx_jane"
File "_tags", line 1, characters 6-28:
Warning: the tag "package(core,ppx_jane)" is not used in any flag or dependency declaration, so it will have no effect; it may be a typo. Otherwise you can use `mark_tag_used` in your myocamlbuild.ml to disable this warning.
+ /Users/David/.opam/4.02.3/bin/ocamldep.opt -modules -pp refmt -impl accum2.re | tee accum2.re.depends accum2.ml.depends
accum2.re: Core Float In_channel
+ /Users/David/.opam/4.02.3/bin/ocamlc.opt -c -g -thread -pp '-g -thread' -pp refmt -o accum2.cmo -intf-suffix .rei -impl accum2.re
File "accum2.re", line 1, characters 5-13:
Error: Unbound module Core
Command exited with code 2.
Compilation unsuccessful after building 2 targets (0 cached) in 00:00:00.

我该如何使用Reason和Core进行开发?

学习其语法十分简单,只需几个小时即可理解。但对于非OCaml用户来说,关于如何使用Reason的文档却是几乎为零。


你在提问后是否已经完成编译了?我目前也在遇到同样的问题。 - Seneca
很抱歉,我还是卡在同一个步骤上。如果没有更深入的 OCaml 工具知识,这是不可能的。这与重建有关,但它是一个 bash 脚本,在 ocamlbuild 周围做了很多事情,所以我甚至不知道大部分输出的含义。 :( - David Pelaez
3个回答

3

最近在Reason存储库中似乎已经进行了错误修复。基本上,由于rebuild其实是一个reasonbuild的包装器,因此可以通过直接运行reasonbuild来解决该问题:

env OCAMLFIND_COMMANDS="ocamlc=$(which reopt)" reasonbuild -use-ocamlfind accum.native

事实上,reasonbuild -use-ocamlfind accum.native 在这里也可以使用。

这是来自头部的吗?还是在稳定版本中?我认为在0.6版本中它仍然不起作用。 - David Pelaez
从GitHub存储库来看,目前似乎只有在主分支中才能安装reason,可以使用OPAM从此提交中安装reason,例如 opam pin add -y reason 'https://github.com/facebook/reason.git#44aa9f4695e14c247c29c4fbc98ca10dcf332eab',但由于这不是一个发布版本,因此可能不建议这样做。 - Mikhail

3
基本上在 https://janestreet.github.io/installation.html 中指示的标签必须被添加,加上三个用于此情况的标志和值:
  • -linkpkg 用于静态链接。
  • -pp refmt 表示 ReasonML 预处理器。
  • -impl file.re 告诉程序要读取哪个文件。
所以如果文件名为 accum.re,则可以使用以下命令将其编译成本地二进制文件: ocamlfind ocamlc -g -thread -package ppx_jane -package core -pp refmt -linkpkg -o accum.native -impl accum.re

0

我猜 rebuild 是 ocamlbuild 的一个包装器。只需使用参数 -use-ocamlfind 调用它即可。


这确实是我认为的,但这几乎不是一个解决方案。如果您能提供真正的指示,那将不胜感激。我尝试过使用-pkg core,也尝试了使用-use-ocamlfind,但都没有成功。 - David Pelaez

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