What is ReasonML? Where does it come from? What can I do with it?
ReasonML is an object-functional programming language that provides a different syntax for writing OCaml code and can be transpiled into JavaScript code using BuckleScript. A comparison between OCaml and ReasonML can be found on ReasonML’s official documentation.
The ReasonML programming language was created at Facebook and I found out about it thanks to Nick Graf’s Egghead course Get Started with Reason. I started taking notes while watching the course and I ended up with this post (so thank him for the code examples).
If you want to know more about the language, Dr. Axel Rauschmayer has written a wonderful book about it that you can read online for free: Exploring ReasonML and functional programming.
What I Like and Dislike so Far
I like…
Inferred types
The possibility of creating custom types and variants
The compiler warns you if your switches are not exhaustive (if you’re forgetting cases)
Code suggestions underneath the command line are cool
Compatibility with JS and OCaml
Lexical scoping
If is an expression that can be evaluated into a value (in other languages it is only an statement)
Syntax of switch expressions
Objects (or records) defined in a similar way as in TypeScript
Destructuring objects (records) in a similar way as in JavaScript
Spread operator as in JavaScript
Combinations of variants with switch expressions are great
You can match specific cases in a switch
There’s no null: variants None and Some can be used instead
You can partially apply arguments in functions (automatic currying)
Labeled parameters (you can apply then in any order you want)
Optional parameters
Pipe operator for function composition
Nested structures can directly be compared for equality
Structural == and referential equality === operators
Powerful pattern matching
I dislike…
Shadowing is allowed (let variables can be redefined)