7

I'm new to OCaml and I'm trying to try (:P) Facebook Reason syntax. I cannot find a way to make this compile because if cannot find the Core module (already installed with opam).

I'm trying to compile a sample program from 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.

When I have this in _tags (from the instructions in 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?

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.

David Pelaez
  • 1,374
  • 1
  • 13
  • 16
  • Have you achieved compilation since asking this question? I'm currently struggling with the same issue. – Seneca May 29 '16 at 18:17
  • I'm afraid not. Still stuck with the same step. Without deeper knowledge into OCaml tooling it's impossible. This has something to do with what rebuild that but it's a bash script doing many things around ocamlbuild so I have not idea what most of the output even means. :( – David Pelaez May 30 '16 at 03:56

3 Answers3

3

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:

  • -linkpkg for static linking I assume
  • -pp refmt indicating the ReasonML preprocessor
  • -impl file.re to tell what file to read

So if the file's called accum.re it can be compiled to a native binary with:

ocamlfind ocamlc -g -thread -package ppx_jane -package core -pp refmt -linkpkg -o accum.native -impl accum.re

David Pelaez
  • 1,374
  • 1
  • 13
  • 16
3

It seems there has been a recent bug fix of the issue in the 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:

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

In fact, reasonbuild -use-ocamlfind accum.native also works here.

Mikhail
  • 31
  • 4
  • is this from head? or is this in stable? In 0.6 I think it still doesn't work – David Pelaez Jul 22 '16 at 21:09
  • From the GitHub repo it seems this is currently only in master, it's possible to install reason from this commit with OPAM, e.g. `opam pin add -y reason 'https://github.com/facebook/reason.git#44aa9f4695e14c247c29c4fbc98ca10dcf332eab'`, but as this is not a release this is probably not recommended – Mikhail Jul 25 '16 at 11:37
0

I guess rebuild is a wrapper around ocamlbuild. Just call it with the parameter -use-ocamlfind.

Drup
  • 3,679
  • 13
  • 14
  • That's indeed what I think it's but it's hardly a solution. If you could help with real indications that would be much appreciated. I tried with `-pkg core` also using `-use-ocamlfind` without any luck. – David Pelaez May 30 '16 at 03:57