7

我是 OCaml 的新手,我正在尝试 (:P) Facebook Reason 语法。我找不到编译的方法,因为如果找不到核心模块(已经安装了 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 与 Reason 一起使用?

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

4

3 回答 3

3

似乎最近在 Reason 回购中对该问题进行了错误修复。基本上,由于rebuild结果是一个包装器,reasonbuild因此可以通过直接运行来解决该错误reasonbuild

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

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

于 2016-07-21T19:34:56.050 回答
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

于 2016-05-30T17:22:25.473 回答
0

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

于 2016-05-29T00:34:34.980 回答