ReasonML in 2020
Published 11 months ago • 6 min read
The one where I talk about the goofy mess ReasonML has become.
My Top 5 ReasonML Features
- Immutable by default
- Curried functions
- Switch statement doubles as pattern-matching
- Prioritizes linked lists over arrays
The pain point with ReasonML is JS interop. ReasonML actually has a good JS interop story (compared to a language like Elm .) If you want to access something you'd normally have global access to in JS, you have to pull it out of the
Js module from BuckleScript. Want to map over a list or array? The method is in the standard library, but which standard library should you use? The ReasonML one is the same as OCaml's, there's a BuckleScript library called Belt, and then there's another one called Js. The ReasonML one is structured like an FP library. The array methods take the function first and then the collection.
let mapper = item => item + 1 let collection = [|1,2,3|] Array.map(mapper, collection)
Js have the same, but they include
let mapper = item => item + 1 let collection = [|1,2,3|] Js.Array2.map(collection, mapper)
Other People's Code
Another major pain point is working with third-party libraries. If you're writing logic that's all your own code, working with ReasonML is easy-peasy. The moment you start pulling in other people's code, you start having to do this.
[@bs.module "lodash"] external kebabCase: string => string = "kebabCase"
…for pretty much everything. If you thought getting types for TypeScript was a pain sometimes, ReasonML is much worse. There are community-backed binding packages you can
Recently, the team behind BuckleScript (not the ReasonML-proper team) announced a newer syntax for BuckleScript version 8.2. It isn't backwards-compatible. The BuckleScript compiler will continue to compile
.re files written in the ReasonML syntax, but now there will be
.res files that have a different syntax that's geared towards being more JS developer-friendly. Then they announced they're rebranding as ReScript. So the BuckleScript name is dead, except that it isn't. You still need to install
rescript packages for you to install yet. The standard library is still called Belt, which was a naming scheme to work with the BuckleScript name. Support for the new syntax in the
refmt code formatter (think Prettier) and the syntax highlighters for code editors isn't ready yet (as of September 2020).
If you were going to help someone learn Reason, what would you even tell them to learn? There's Reason, ReScript (which everthing around it is still named after BuckleScript), and the Reason and ReScript teams have vastly different goals at this point in time (and for the forseeable future as well). Reason and ReScript have syntaxes that are mostly the same, but aren't interchangble. Reason and OCaml code can be translated 1-to-1. ReScript can convert Reason syntax straight to ReScript syntax, so there's a path forward. But if you want to have native code and browser-focused code that shares the same logic, you're now forced to have different syntaxes and filetypes floating around in the same project. It's a mess. Maybe if the ReScript team waited to announce everything all at once instead of parsing out changes and updates once a week over a period of months, the messaging and project direction wouldn't feel so incoherent. I believe they are a group of smart people that want to create a better alternative to TypeScript, but they're leaving the native story behind and the Reason community is going to fragment.