Wiki Article
Reason (programming language)
Nguồn dữ liệu từ Wikipedia, hiển thị bởi DefZone.Net
| 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 | 3.17.2[2] |
| 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]
Language characteristics
[edit]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]
Example
[edit]type schoolPerson = Teacher | Director | Student(string);
let greeting = person =>
switch (person) {
| Teacher => "Hey Professor!"
| Director => "Hello Director."
| Student("Richard") => "Still here Ricky?"
| Student(anyOtherName) => "Hey, " ++ anyOtherName ++ "."
};
History
[edit]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]
See also
[edit]- Elm – A functional language that uses an abstraction called ports to communicate with JavaScript
- PureScript – A strongly-typed, purely-functional programming language that compiles to JavaScript
References
[edit]- ^ a b Walke, Jordan (May 16, 2016). "Initial Release: reasonml/reason". GitHub. Retrieved December 22, 2025.
- ^ "Release 3.17.2". November 30, 2025. Retrieved December 1, 2025.
- ^ "Melange". Reason Documentation. Retrieved December 20, 2025.
- ^ Rafatpanah, Raphael; D'mello, Bruno Joseph (February 28, 2019). ReasonML Quick Start Guide. Packt Publishing. p. 6.
- ^ Eisenberg, J. David (April 9, 2019). Web Development with ReasonML. Pragmatic Bookshelf. p. 170.
- ^ a b Eisenberg 2019, p. 15.
- ^ Eisenberg 2019, pp. 1–4.
- ^ "The OCaml Language - Parenthesized Expressions". ocaml.org. Retrieved September 30, 2025.
- ^ De Simone, Sergio (November 10, 2017). "Facebook Overhauls ReasonML Syntax in Reason 3". InfoQ. C4Media. Retrieved January 3, 2026.
- ^ Rafatpanah & D'mello 2019, p. 17.
- ^ "Way, Way, Waaaay Nicer Error Messages!". Reason. August 25, 2017. Retrieved January 3, 2026.
- ^ ReasonReact home page
- ^ Rafatpanah & D'mello, p. 1.
- ^ ReasonConf (November 29, 2019). Jordan Walke - React to the Future (video). Retrieved December 21, 2025 – via YouTube.
- ^ "Reason". Facebook. Archived from the original on May 17, 2016.
- ^ "BuckleScript: The 1.0 release has arrived!". Bloomberg. September 8, 2016. Retrieved December 21, 2025.
- ^ "Why Melange". Melange Documentation Site. Retrieved December 21, 2025.
- ^ a b Zhang, Hongbo (February 7, 2021). "A Short History of ReScript (BuckleScript)". OCaml Discourse. Retrieved December 21, 2025.
- ^ Lou, Cheng (July 1, 2020). "A New Syntax for BuckleScript". ReScript. Retrieved December 21, 2025.
- ^ ReScript Team (August 10, 2020). "BuckleScript & Reason Rebranding". ReScript. Retrieved September 11, 2022.
- ^ Yang, Danny (December 2022). "Introduction". Introducing ReScript: Functional Programming for Web Applications. Apress.
- ^ Monteiro, António (June 2, 2023). "ANN: Melange 1.0 – compile OCaml / ReasonML to JavaScript". OCaml. Retrieved May 24, 2024.
- ^ Monteiro, António (June 2, 2023). "Melange 1.0 is here". Retrieved December 21, 2025.
External links
[edit]- Official website

- Reason Project Organisation on GitHub
- Melange documentation site
- ReasonReact