Why a new language?
A compiled language has many benefits. One of them being able to control the output.
There has been made measures to alleviate this, like proptypes and Immutable JS, but this is more a treatment of the symptoms, and not the underlying disease.
Lets see how this looks with a simple addition function
Looks pretty much the same right? So what is the difference?
But hey mister blog man!?
The ReasonML code is just the same? How is that better then?
Because it compiles before it can be run. This means that the types will be inferred to integers, and the compiler will be angry if you use this function and give it a string.
Well, in reason there is different operators for different types, and
+ is the operator for adding integers together, this is why the compiler can infer that it needs to integers. Had i written
+. the types would be inferred to floats.
In ReasonML the switch is a all powerful pattern matching tool that will help you do all kinds of nice conditional logic with zero to none in terms of overhead.
And what better example is there than FizzBuzz
Now, when we talk about reading compiled code, we usually shudder at the thought. But when it comes to compiled ReasonML, it is not that bad.
Even though the output is very verbose, it is very easy to read. I will leave analyzing the differences between the two to you, the reader, but i will just hint that
_ is a wildcard and
| is a break in statements.
Next week i will show you how i made a Knitting app for my wife using ReasonML and ReasonReact.