[英]How to use Jane Street's Core with Reason?
I'm new to OCaml and I'm trying to try (:P) Facebook Reason syntax. 我是OCaml的新手,我正试图尝试(:P)Facebook Reason语法。 I cannot find a way to make this compile because if cannot find the Core module (already installed with opam). 我无法找到一种方法来进行编译,因为如果找不到Core模块(已经安装了opam)。
I'm trying to compile a sample program from Real World OCaml 我正在尝试从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.);
This is the command I'm using for compilation: rebuild accum.native
. 这是我用于编译的命令: rebuild accum.native
。
When I have this in _tags
(from the instructions in https://janestreet.github.io/installation.html ) 当我在_tags
有这个时(来自https://janestreet.github.io/installation.html中的说明)
true: package(core,ppx_jane)
true: thread,debug
My error changes but I still don't know what to do: 我的错误发生了变化,但我仍然不知道该怎么做:
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.
What do I have to do to use Core with Reason? 使用Core with Reason需要做什么?
Adopting the syntax is pretty easy and I have only been reading for a couple hours, but there's zero docs about how to use Reason for non OCaml users. 采用语法非常简单,我只阅读了几个小时,但是关于如何对非OCaml用户使用Reason的文档是零。
It seems there has been a recent bug fix of the issue in the Reason repo. 似乎最近在Reason repo中修复了该问题。 Basically, since rebuild
turns out to be a wrapper around reasonbuild
it's possible to work around the bug by running reasonbuild
directly: 基本上,由于rebuild
是一个围绕reasonbuild
的包装器,因此可以直接运行reasonbuild
来解决这个问题:
env OCAMLFIND_COMMANDS="ocamlc=$(which reopt)" reasonbuild -use-ocamlfind accum.native
In fact, reasonbuild -use-ocamlfind accum.native
also works here. 实际上, reasonbuild -use-ocamlfind accum.native
也适用于此。
Basically the tags indicated in https://janestreet.github.io/installation.html have to be added plus three more flags and values used for this case: 基本上,必须添加https://janestreet.github.io/installation.html中指示的标记以及另外三个用于此案例的标记和值:
-linkpkg
for static linking I assume -linkpkg
用于静态链接我假设 -pp refmt
indicating the ReasonML preprocessor -pp refmt
指示ReasonML预处理器 -impl file.re
to tell what file to read -impl file.re
告诉要读取的文件 So if the file's called accum.re
it can be compiled to a native binary with: 因此,如果文件名为accum.re
则可以将其编译为本机二进制文件:
ocamlfind ocamlc -g -thread -package ppx_jane -package core -pp refmt -linkpkg -o accum.native -impl accum.re
I guess rebuild
is a wrapper around ocamlbuild. 我想rebuild
是ocamlbuild的包装器。 Just call it with the parameter -use-ocamlfind
. 只需-use-ocamlfind
参数-use-ocamlfind
调用它-use-ocamlfind
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.