| Reason | |
|---|---|
| | |
| Paradigms | Multi-paradigm: functional, imperative, modular, object-oriented |
| Family | ML: Caml: OCaml |
| Designed by | Jordan Walke |
| First appeared | May 16, 2016 [1] |
| Stable release | |
| License | MIT |
| Filename extensions | .re, .rei |
| Website | reasonml |
| Influenced by | |
| OCaml, JavaScript | |
Reason, also known as ReasonML, is a programming language and toolchain that is part of the OCaml programming language ecosystem. Reason uses many syntax elements from JavaScript, compiles to native code using OCaml's compiler toolchain, and can compile to JavaScript using the Melange compiler. [3]
Since Reason is an alternate syntax to OCaml, they share the same characteristics. Both languages are general-purpose, [4] functional and object-oriented. [5]
While Reason compiles down to native code via OCaml's toolchain, it specifically differs in its syntax, error messaging, and editor tooling. This allows Reason to provide an experience more similar to JavaScript or TypeScript for developers.
Reason’s syntax is more similar to JavaScript and other C-style languages than to OCaml. For example, Reason tends to use curly braces to delimit blocks [6] and semicolons for separating statements, [7] while OCaml primarily uses parentheses or begin/end keywords to delimit blocks [8] , with nothing separating declarations. Reason also defines functions via an arrow-like syntax (rather than OCaml's fun keyword), [6] and calling a function requires parentheses around its arguments. [9] Other notable differences include naming the pattern matching keyword switch (instead of match), [10] and reformatting error messages to be more familiar to JavaScript programmers. [11]
The Reason community officially provides ReasonReact as a solution for web applications based on the React framework. [12] [13]
typeschoolPerson=Teacher|Director|Student(string);letgreeting=person=>switch(person){|Teacher=>"Hey Professor!"|Director=>"Hello Director."|Student("Richard")=>"Still here Ricky?"|Student(anyOtherName)=>"Hey, "++anyOtherName++"."};Jordan Walke, creator of the React web framework, first released Reason in 2016 while employed at Facebook. [1] [14] [15]
In the same year, Bloomberg L.P. introduced BuckleScript, a compiler which compiled OCaml to JavaScript. [16] As both projects were influenced by JavaScript, Reason and BuckleScript soon became an integrated toolchain, allowing Reason to target JavaScript. [17] [18]
However, the Reason team and the BuckleScript team had different priorities. The Reason team wanted to maintain compatibility with the OCaml ecosystem, while the BuckleScript team wanted to be able to change the syntax to give the best developer experience to JavaScript programmers. [18]
In 2020, BuckleScript introduced a new syntax that started to diverge from Reason. [19] A month later, the BuckleScript team rebranded its toolchain to ReScript, to focus solely on the JavaScript ecosystem and essentially becoming its own language, distinct from Reason. [20] [21]
To maintain the ability for Reason to target JavaScript, António Monteiro forked a version of BuckleScript before it was rebranded as ReScript, and changed it to bring it closer to the OCaml ecosystem. The fork, named Melange, released its first stable version in 2023. [22] [23]