Reason got an Update

K - Oct 30 '17 - - Dev Community

Cover image by GotCredit on Flickr, cropped by me.

As you may heard, Facebook is out to do its own thing on functional programming languages. They created Reason, a language with the power of OCaml, but a more JavaScript like syntax.

Now this new language was lifted to version 3 that came with a bunch of syntax updates.

    let myFunction myArgument => ...
Enter fullscreen mode Exit fullscreen mode

becomes

    let myFunction = (myArgument) => ...
Enter fullscreen mode Exit fullscreen mode

Which looks a bit saner coming from JS, I think. The old version somehow looked a bit like a mix of a regular function definition where let is used instead of function and a arrow function definition, all without parenthesis.

Also, there are changes on the functions call site, more parenthesis for everyone!

    myFunction "Hello";
Enter fullscreen mode Exit fullscreen mode

becomes

    myFunction("Hello");
Enter fullscreen mode Exit fullscreen mode

I did a few projects in LiveScript, back in the pre-ES2015 days, and grew rather fond of the minimal syntax, but I have to admit, often parenthesis help to make things a bit clearer.

The arrow functions got an update too.

    {
      add: fun a b => a + b
    }
Enter fullscreen mode Exit fullscreen mode

becomes

    {
      add: (a, b) => a + b
    } 
Enter fullscreen mode Exit fullscreen mode

Again, a question of taste, but yes if you know JavaScript, you'll pretty much feel at home here.

Then there are the named arguments. They are a bit like when you make a function in JavaScript, that takes an object instead of multiple arguments, so you don't have to adhere to the position of the arguments and see on call site what each argument is called.

    let myFunction ::url ::method => ...
Enter fullscreen mode Exit fullscreen mode

becomes

    let myFunction = (~url, ~method) => ...
Enter fullscreen mode Exit fullscreen mode

On the call site it was changed too.

    myFunction ::url="http://dev.to" ::method="POST";
Enter fullscreen mode Exit fullscreen mode

becomes

    myFunction(~url="http://dev.to", ~method="POST");
Enter fullscreen mode Exit fullscreen mode

String concatination is now ++ so

    "abc" ^ "def"
Enter fullscreen mode Exit fullscreen mode

becomes

    "abc" ++ "def"
Enter fullscreen mode Exit fullscreen mode

Different from the JavaScript version, but a bit closer to + I guess.

The negation operator also got a more JavaScript like representation

    not expression;
Enter fullscreen mode Exit fullscreen mode

becomes

    ! expression;
Enter fullscreen mode Exit fullscreen mode

Also, calling a function without parameters required to pass it () which kinda looked like calling it in JavaScript even tho the concept seemed to be a bit different, but there was a space between the function name and the ()

    myFunction ();
Enter fullscreen mode Exit fullscreen mode

becomes

    myFunction();
Enter fullscreen mode Exit fullscreen mode

A minor change, but these tiny seemingly useless spaces probably gave people the heebie jeebies.

Conclusion

Reason moves more and more from OCaml to JavaScript, so starting with it has never been easier. Many people have complained about getting rid of the cool OCaml syntax and cluttering it with JavaScript trash, but I think this syntax convergence is a must for adoption.

Also, OCaml doesn't go away and I already heard that people started with Reason and switched to OCaml later, because they found the syntax more light weight.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player