5 ms·
Reason/OCaml has brought back my love of programming. It is functional, statically typed, and extremely pragmatic. You can program it just like an imperative la
by jasim 9y ago
Reason/OCaml has brought back my love of programming. It is functional, statically typed, and extremely pragmatic. You can program it just like an imperative language and write mutating code without any ceremony, or you can write purely functional code and get the benefits of equational reasoning.
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 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.
- cies 9y ago> The pragmatism comes from the fact that you can use it today on the browser. 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!
- klibertp 9y ago> OCaml (and therefor Reason) is FP first and OO on top of 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.
- jasim 9y agoI would love to learn more about this. I've been programming in OCaml for a few months now and have stuck to records and immutable updates and modules for grouping behaviour. I really like this style compared to the object-oriented programming I was doing in Ruby. 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?
- erokar 9y agoOne of the things I dislike most about JavaScript is the syntax. I always thought the Javaesque syntax hid the some of the nice semantics underneath. CoffeeScript and LiveScript help reveal that language. 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.
- klibertp 9y agoIt's not ALGOL-like syntax that's a problem with JS, it's the fact that for decades the JS syntax was frozen, without any significant additions to the initial, very minimal, syntax. The same is true for JS standard library: it's almost non-existent compared to Python or Ruby, and even Lua has more builtins (IIRC). 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.
- erokar 9y agoI'm not complaining that JS isn't Haskell. Underneath the C/Java syntax JS is a small, simle, Lispy, dynamic language — if you like that kind of thing. JS' syntax hide that. CoffeeScript helped reveal it. > In other words, you can have good looking FP support with braces and semicolons. Of course. But why would you?
- jasim 9y agoI love braces and semicolons and my biggest gripe with CoffeeScript and HAML and Python was that they used space to delimit blocks. The good thing about braces is that moving code around is easy and it makes auto-formatting possible. refmt, prettier etc. are all amazing to have. But in terms of syntactic preferences, it is quite subjective and I wouldn't claim there is one true answer.
- christophilus 9y agoI agree. I wish the Reason team would just use BuckleScript and pure OCaml syntax. I really don't like the addition of syntactic noise that Reason has introduced.
- hbbio 9y agoFYI, this has been around for a long time ;) I was the creator of the Opa project, cf. http://opalang.org http://opalang.org which did almost that since 2009...