ReasonML: A new language that leverage both JavaScript & OCaml ecosystems

Facebook’s liking for OCaml isn’t a news to anyone. With a strong type checker – Flow, Facebook already has given the programming world a smart, proactive Type System that is built on OCaml. But they didn’t stop at that. In the form of ReasonML, Facebook has introduced an object-functional programming language that leverage OCaml along with, wait for it, Javascript. The language has all goodness of OCaml and all ease to be interoperable with JavaScript.

Basically, ReasonML can be seen more as a new syntax rather than a new language. It is basically OCaml but written to be more programmer friendly than it already is. To explain in simplest terms, ReasonML is OCaml going full C in its syntax. This gives the JavaScript programmers, an ease of working with OCaml with all its good features and minus the idiosyncrasies. So, Reason has the fast processing and features of JavaScript (including ES2030) and solid static typing of OCaml. That’s Nice.

Why Reason?

Seriously, are we still asking this question? Okay, let’s go through the list and see for ourselves:

Solid Static Typing

In case I forgot to mention, Reason is built on and around OCaml. Static Typing is something it can be relied upon for. JavaScript is a dynamic and interactive UI builder, but it lacks in one very obvious feature – Type System. Reason ensures that you don’t have to grep your way through your JavaScript for hours, to find that ‘var1’ was a string and not a float.

Making the Goodness of OCaml, More Good

As told earlier, Reason is OCaml on a crash course for C language. In fact, Reason can very well be called as a simpler yet pragmatic version of OCaml. The code built in Reason is not only built faster but smaller in size with exact same effect and features. So, with Reason, OCaml has

  • Better Tooling i.e. support for other testing and editing tools
  • Much More Easier interoperability with JavaScript. As a matter of fact, it can be seen as creating a better version of JavaScript.
  • Better readability of the final built code
  • Standard Libraries better than what OCaml already has, including the popular libraries like React.

Learning On its Own

Just like Flow, Reason also has the inherited feature of incremental learning. It can understand the semantics and dependencies of your JavaScript Modules and even convert the codebase in case of any changes in any files or in the server.

The point is, why learn a new language for your app when you can just work with the old one… With a newer ease and better results.

ReasonReact

If you think, Infinity War is the best crossover ever, you’ve not seen this. On one hand, we have ReactJS, one of the best and most popular Javascript libraries for dynamic and interactive UIs of all times. And on the other hand, we have smart, solid and easily interoperable – Reason. And when we join them both we get the Future of Interactive UIs, ReasonReact.

Maintained by Facebook itself, React is a pretty efficient library on its own. To count a few of its features we can list:

  • The capacity of easy and convenient adaption not only with the ecosystem but also developing into something new.
  • Seamless support for JSX – One of the places where JavaScript and HTML are still together
  • Better Server-Side communication than ever
  • Availability of the latest ECMAScript
  • And, of course, what programmers like most – Free and open source

Now imagine all this with leverage for JavaScript as well as OCaml ecosystems. If this doesn’t make you like Reason, or rather ReasonReact, I don’t know what will. Here’s a list of some evident gifts the Reason and React together bring for the programmers:

Reliability of Reason

Think it this way, React is a library written in JS. Reason is what makes JS stronger and more efficient. Mix them together and voila! We have a library written in a strongly typed fast processing JavaScript that is made to provide all the features of React.

Adaptability of React

Adapting React for future is one thing and doing the same with the Reliability of Reason is an entirely different phenomenon. ReasonReact can, essentially, serve as a playground to develop React for future.

Seamless Integration

Even if you have an existing application, a ReasonReact code very easily integrate with it. Because at the heart of it, it’s still JavaScript with more efficient capabilities.

Quick Results

The simple equation for speed – JS times OCaml. The library will process in single-digit milliseconds.

Conclusion

Basically, if you start cleaning up JavaScript and throw in some solid static typing and some syntaxes of an Object Functional Language, that’s ReasonML for you right there. Reason just makes OCaml much better which, in turn, makes JS much-much better. And when you write a library like React in so much better JS, you can expect much-much-much better results. To simply put, Reason is not something new but something old done better. For more information about OCaml, Reason, React or JS itself, keep following us.

Mapu

I am a technology freak with passion for UI technology.

Leave a Reply