Using Rescript/ReasonML with react

I created a react application using:
bsb -init ontology-editor -theme react-hooks

It creates ReasonML .re files. I renamed some of them to .res, but , .res files do not support ReasonML syntax, such as document##createElement(...). After I edited the incompatibilities, everything worked fine. Questions:

  1. I understood that Rescript was backward compatible with ReasonML (no breaking changes). Isn’t that the case?
  2. Can I freely mix .re and .res in a react project? Will the compiler recognize them without any need to alter the build files?
  1. ReScript has a new syntax, different from ReasonML syntax. It is not backward-compatible.
  2. Yes, you can mix .res/.re/.ml files (and their interfaces) freely within a project and the ReScript compiler will understand them all.

But ReScript docs says that backward compatibility for existing bucklescript codebases is one of their main goals.

1 Like

The ReScript compiler supports three syntaxes:

  • OCaml syntax. Equivalent to upstream OCaml syntax
  • Reason v3.6 syntax. Equivalent to upstream Reason v3.6 syntax
  • ReScript syntax. Not backward-compatible with Reason syntax

With the first two syntaxes, it provides backward-compatibility with existing BuckleScript (OCaml and Reason) codebases.

1 Like

I am confused about the relationship between the 3 syntaxes. I understood that the ReScript compiler would compile:

  • OCaml -> javascript
  • Reason -> OCaml -> javascript
  • ReScript -> OCaml -> javascript

If I needed, the compiler had the option to compile Reason or ReScript to OCaml. I could then
compile OCaml to native code (using another OCaml compiler). Is that the case?

The ReScript compiler takes those three syntaxes as input and produces JavaScript output only. It does not produce OCaml output. Targeting native OCaml is a non-goal of ReScript.