The rise of ReasonML
- A brief history of ReasonML
- Static Typing
- Functional Paradigm
- Frontend Usage
- Backend Usage
A brief history of ReasonML
ReasonML is a new syntax for the OCaml programming language created by Facebook.
If I had to describe OCaml in just a few words, I would say:
- Strongly typed
- Battle tested and mature
- Fast (really, really fast)
Compiling to OCaml, means that your code can be compiled a second time to bytecode, assembly or native code.
ReasonML is a pretty new language, so it’s clear that still doesn’t have all the features you may need in order to write a complex application.
npm library or write your own modules in OCaml.
Pretty impressive, isn’t it? 🐫
OCaml is a static typed programming language.
That means that you can finally throw away Flow and Typescript! 😁
Ok, I’m just kidding, but static typing in ReasonML can be seriously painless (and very efficient).
Let’s do an example.
I’m gonna use
rtop, which is an amazing interactive command line tool for ReasonML.
foo is a
This is called type inference.
Of course, I can always explicitly declare the type of any binding:
Pretty similar to TypeScript, isn’t it? 😊
Functional programming helps you a lot with concurrency (just think about Erlang and its concurrency model), functions are more predictable and easier to test, and you are less likely to get some unexpected side-effects during runtime.
Take as an example the function above: using a simple
map method, I’ve tried to reassign a value to
foo binding. The compiler thankfully prevent this kind of behaviours.
Just take the following code as an example:
Guess what will this program output? “Hey John Doe!”
Now imagine how powerful and useful can be this feature.
We’ve previously seen how the compiler reports errors. ReasonML compiler is rock solid and helps you a lot with debugging and optimization of your code.
But what does it compile?
Or, if you’re a brave person, you can compile the OCaml code to assembly or native code (take a look at this Gist).
But remember that OCaml native has a single digit milliseconds startup time and can run on iOs, Android and assembly, so you’re able to run an high performance program to any platform you may wish!
As we’ve seen, ReasonML is a language that’s worth learning.
It’s fun to write, fast to execute and has an awesome compiler.
That means that a single developer can code both the server and the UI, breaking the line between backend software engineers and frontend developers.
I know that ReasonML is still young. But, if I were in your shoes, I’d give it a chance! 😊🐫