[英]How to use Jane Street's Core with 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的文檔是零。
似乎最近在Reason repo中修復了該問題。 基本上,由於rebuild
是一個圍繞reasonbuild
的包裝器,因此可以直接運行reasonbuild
來解決這個問題:
env OCAMLFIND_COMMANDS="ocamlc=$(which reopt)" reasonbuild -use-ocamlfind accum.native
實際上, reasonbuild -use-ocamlfind accum.native
也適用於此。
基本上,必須添加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
我想rebuild
是ocamlbuild的包裝器。 只需-use-ocamlfind
參數-use-ocamlfind
調用它-use-ocamlfind
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.