How ReasonML could become the recommended way to write future React applications

ReasonML, created by the same person that originally created React, is a new syntax for the OCaml language that is meant to be welcoming to JavaScript developers. Reason lets you write simple, fast and quality type safe code while leveraging both the JavaScript & OCaml ecosystems.

ReasonML is a powerful functional language built by Facebook, and created by Jordan Walke who initially created React. It is not a brand new language, but a syntax over the language OCaml. OCaml is a very mature, battle tested language with extremely fast native compilation.

OCaml provides a functional syntax, with immutable data structures and 100% type safety. The first prototypes of React were actually built in a language called SML, a distant cousin of OCaml.

Reason provides a syntax on top of OCaml that caters to developers more familiar with Javascript, whilst maintaining the powerful features of the underlying Ocaml language. Out of the box Reason uses Ocaml’s native compiler, to compile to bytecode that can run on a wide variety of platforms. In addition provides the capability to compile to Javascript with the help of a tool called BuckleScript.

Bucklescript is a tool built by Bloomberg which compiles OCaml or Reason into readable Javascript with smooth interoperability with existing Javascript libraries. In fact due to optimisations that Bucklescript can make when using immutable, type safe data structures, code written in Reason or Ocaml and compiled by BuckleScript into Javascript can have better performance out of the box than the same functionality written in Javascript.

With the tools that Bucklescript provides incorporated into the language, Reason can be fully interoperable with existing Javascript codebases and npm packages. Using plugins for Babel or Webpack, Reason can be incrementally introduced into another Javascript codebase, allowing developers to gradually introduce Reason’s benefits over time.

Along with providing a familiar syntax for Javascript developers, Reason also aims to provide first class support for React. Reason React is a separate library that provides React bindings for use in Reason applications compiled to Javascript. Reason React expands on the React framework and leverages the features of the Reason language to provide language level application routing, data management and component composition. Writing React applications in Reason using Reason React allows you to build applications that are safe, statically typed, simple and lean.

By providing a familiar syntax, and gathering together an ecosystem of tools and libraries, ReasonML has the potential to push the Javascript community further towards functional programming, strong type safety, immutable data structures and native compilation with all of the technical and productivity benefits those features provide. With its tight integration with React, Reason might become the recommended way to write React applications in the future.