![]() | |
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 general-purpose, high-level, multi-paradigm, functional and object-oriented programming language and syntax extension and toolchain for OCaml created by Jordan Walke, who also created the React framework, at Facebook. [3] [4] Reason uses many syntax elements from JavaScript, compiles to native code using OCaml's compiler toolchain, and can compile to JavaScript using the ReScript compiler. [5]
The Reason community officially provides ReasonReact as a solution for React-based web applications. [6]
Reason was originally compiled to JavaScript using the BuckleScript compiler, [7] which was created at Bloomberg L.P.
In 2020, the BuckleScript and Reason toolchain was rebranded to ReScript, essentially creating a separate language that had different syntax from Reason and only compiled to JavaScript. [8]
BuckleScript was forked to Melange [9] to continue to support compiling OCaml to JavaScript.
While Reason compiles down to native code via OCaml's toolchain, it specifically differs in its syntax, error messaging, and editor tooling. [10] This allows Reason to provide an experience more similar to JavaScript or TypeScript for developers, which some may be more familiar with.
While OCaml often relies on Indentation and begin/end keywords, Reason tends to use curly braces to delimit blocks and semicolons for separation of expressions. Like JavaScript, Reason also defines functions via arrow-like syntax. Other notable differences include usage of a switch construct (instead of a match construct) and a reformatter for error messages.
typeschoolPerson=Teacher|Director|Student(string);letgreeting=person=>switch(person){|Teacher=>"Hey Professor!"|Director=>"Hello Director."|Student("Richard")=>"Still here Ricky?"|Student(anyOtherName)=>"Hey, "++anyOtherName++"."};