Reason (programming Language)
   HOME

TheInfoList



OR:

Reason, also known as ReasonML, is a general-purpose, high-level,
multi-paradigm Programming languages can be grouped by the number and types of Programming paradigm, paradigms supported. Paradigm summaries A concise reference for the programming paradigms listed in this article. * Concurrent programming language, Concurrent ...
, functional and
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
and
syntax In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
extension and
toolchain A toolchain is a set of software development tools used to build and otherwise develop software. Often, the tools are executed sequentially and form a pipeline such that the output of one tool is the input for the next. Sometimes the term is us ...
for
OCaml OCaml ( , formerly Objective Caml) is a General-purpose programming language, general-purpose, High-level programming language, high-level, Comparison of multi-paradigm programming languages, multi-paradigm programming language which extends the ...
created by Jordan Walke, who also created the React framework, at
Facebook Facebook is a social media and social networking service owned by the American technology conglomerate Meta Platforms, Meta. Created in 2004 by Mark Zuckerberg with four other Harvard College students and roommates, Eduardo Saverin, Andre ...
. Reason uses many syntax elements from
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
, compiles to native code using OCaml's
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
toolchain, and can compile to JavaScript using the ''ReScript'' compiler. The Reason community officially provides ReasonReact as a solution for React-based web applications.


BuckleScript and ReScript

Reason was originally compiled to JavaScript using the BuckleScript compiler, which was created at
Bloomberg L.P. Bloomberg L.P. is an American privately-held financial, software, data, and media company headquartered in Midtown Manhattan, New York City. It was co-founded by Michael Bloomberg in 1981, with Thomas Secunda, Duncan MacMillan, Charles Ze ...
In 2020, the BuckleScript and Reason toolchain was rebranded to
ReScript A rescript is a public government document. More formally, it is a document issued not on the initiative of the author, but in response to a question (usually legal) posed to the author. The word originates from replies issued by Roman emperors t ...
, essentially creating a separate language that had different syntax from Reason and only compiled to JavaScript. BuckleScript was forked to Melange to continue to support compiling OCaml to JavaScript.


Differences from OCaml Syntax

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 TypeScript (abbreviated as TS) is a high-level programming language that adds static typing with optional type annotations to JavaScript. It is designed for developing large applications and transpiles to JavaScript. It is developed by Micr ...
for developers, which some may be more familiar with. While OCaml often relies on
Indentation __FORCETOC__ In the written form of many languages, indentation describes empty space ( white space) used before or around text to signify an important aspect of the text such as: * Beginning of a paragraph * Hierarchy subordinate concept * Qu ...
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 In electrical engineering, a switch is an electrical component that can disconnect or connect the conducting path in an electrical circuit, interrupting the electric current or diverting it from one conductor to another. The most common type o ...
construct (instead of a match construct) and a reformatter for error messages.


Example

type schoolPerson = Teacher , Director , Student(string); let greeting = person => switch (person) ;


See also

*
Elm Elms are deciduous and semi-deciduous trees comprising the genus ''Ulmus'' in the family Ulmaceae. They are distributed over most of the Northern Hemisphere, inhabiting the temperate and tropical- montane regions of North America and Eurasia, ...
– 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


External links

* *
ReasonReact
{{Authority control Cross-platform free software Extensible syntax programming languages Free and open source compilers Functional languages Object-oriented programming languages ML programming language family OCaml programming language family Pattern matching programming languages Statically typed programming languages Programming languages created in 2016 High-level programming languages Software using the MIT license