A ReasonReact Tutorial
jaredforsyth.com
jaredforsyth.com
The pragmatism comes from the fact that you can use it today on the browser. Unlike most other compile-to-js languages which are fairly new, OCaml is a mature language with a stable ecosystem. Its history dates back to the 80s when Robin Milner et al started building a theorem prover which evolved into a language that can be used for general purpose programming with strong compile-time guarantees thanks to the Hindley-Milner type system.
Reason is a new syntax for OCaml, and it is being lead by Jordan Walke and Cheng Lou. Jordan prototyped the first versions of React in OCaml, and React has planted nubs of FP ideas like immutability, and introduced a functional approach to building composable UIs which has so far been dominated by object-oriented mutation-heavy paradigms. The team is taking it one step further by bringing the entire FP paradigm to the browser.
The Reason syntax is currently functional just like OCaml and Haskell:
let sum a b => a + b;
print_int (sum 1 2);
The Reason team is considering changing it to a syntax that ALGOL-style programmers are familiar with. There are more details here: https://github.com/facebook/reason/pull/1299. So it'd become: let sum(a, b) => a + b;
print_int(sum(1,2));
So in essence Reason can be considered a super-set of Javascript that adds powerful static typing, immutable values, and almost-first-class modules. This will greatly remove a source of friction for programmers new to FP, and in turn should help in the mainstream adoption of a strongly typed functional programming language. I think this would be a wonderful thing for practicing programmers in that more of us will be able to enjoy statically typed FP, and for the industry in general because we can now expect better programming practices and more robust systems.I really hope Reason doesn't make the same mistake and go for a more ALGOL-like syntax. My hope would be that they go for an even cleaner syntax than the current, more like Standard ML and Elm. The semicolons and the curly braces will not be missed.
In other words, you can have good looking FP support with braces and semicolons. It's just that you need to build such support into the language, and for JS it was impossible for a long time.
> In other words, you can have good looking FP support with braces and semicolons.
Of course. But why would you?
But in terms of syntactic preferences, it is quite subjective and I wouldn't claim there is one true answer.
I was the creator of the Opa project, cf. http://opalang.org which did almost that since 2009...
Part of that pragmatism was already available in OCaml since it's inception.
> The Reason syntax is currently functional just like OCaml and Haskell:
Reason does not prohibit --thus "allows-- OO, just as it is available in OCaml. Though both communities prefer FP style. I'd say OCaml (and therefor Reason) is FP first and OO on top of that. Contrary to Ruby's OO first and FP on top of that. Some say OCaml's OO is in there to sell it to mgmt :)
> So in essence Reason can be considered a super-set of Javascript
I do not think that's strictly true, but I get what you're trying to say.
> The Reason team is considering changing it to a syntax that ALGOL-style programmers are familiar with.
I really like the syntax as it is, and kind of hope "for my own sake" they keep it in line with OCaml and Haskell. But if this kind of syntax is needed to bring together a critical mass and start an FP revolution, then it is "just syntax" and I easily compromise on that!
That's a general opinion, which I find quite sad. The object system in OCaml (the 'O' in the name stands for something...) is actually very well designed and is very different from what you may be used to from languages like Java (or even Ruby). It uses structural instead of nominal typing and separates class definition and object construction, while still being statically typed. Actually, lack of this particular OO system in F# is my biggest complaint against it.
Real World OCaml has a chapter on objects and I'll give it one more read. But are there any other articles/links that expands on OCaml's object system and how it compares to conventional OO?
I figured I should share a project I made as well with ReasonReact. I'm a noob to React and frontend programming in general, but I was surprised by how easily it was to pick it up. I created a simple game of Snake over a weekend just to test it out. Great programming experience, great first impression.
edit: live demo: (warning: not mobile friendly) http://192.241.133.216/projects/websnake/index.html
https://github.com/jsdf/reason-react-hacker-news (rather unimaginatively, a hacker news app)
https://github.com/jsdf/lisp.re (native, the start of a lisp in Reason)
It's syntax fixes pretty much every issue I ever had with OCaml as well (and feels pretty nice to write if you're coming from a JS background)
Is there any ongoing or planned effort to integrate web technologies into ReasonML (as in provide up to date and comprehensive typings)?
Further, anything already typed with Flow or Typescript can be converted with this. https://github.com/rrdelaney/ReasonablyTyped
Beyond that, defining js types and interop with Reason/BS has probably been the most pleasant experience in a compile-to lang that I've used.