如何使用Jane Street的Core with Reason?

时间:2016-05-28 23:05:19

标签: ocaml ocamlbuild reason

我是OCaml的新手,我试图尝试(:P)Facebook Reason语法。我无法找到一种方法来进行编译,因为如果找不到Core模块(已经安装了opam)。

我试图从Real World 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.

使用Core with Reason需要做什么?

采用语法非常简单,我只阅读了几个小时,但是有关如何为非OCaml用户使用Reason的零文档。

3 个答案:

答案 0 :(得分:3)

最近在Reason repo中出现了bug fix问题。基本上,由于rebuild原来是reasonbuild的包装,因此可以通过直接运行reasonbuild来解决错误:

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

事实上,reasonbuild -use-ocamlfind accum.native也适用于此。

答案 1 :(得分:2)

基本上,https://janestreet.github.io/installation.html中指示的标记必须添加 plus ,还有三个用于此案例的标记和值:

  • -pp refmt用于静态链接我假设
  • -impl file.re表示ReasonML预处理器
  • accum.re告诉要阅读的文件

因此,如果文件名为ocamlfind ocamlc -g -thread -package ppx_jane -package core -pp refmt -linkpkg -o accum.native -impl accum.re,则可以将其编译为本机二进制文件:

{{1}}

答案 2 :(得分:0)

我猜rebuild是ocamlbuild的包装器。只需使用参数-use-ocamlfind

调用它