Reason (programming language): Difference between revisions

Content deleted Content added
Removed useless URL
Tag: references removed
No edit summary
 
(26 intermediate revisions by 18 users not shown)
Line 1:
{{Short description|Syntax extension and toolchain for OCaml}}
{{Infobox programming language
| name = Reason
| logo = Reason-logo.svg
| logo_size = 200px
| released = {{Start date and age|2016|5|16}}<ref>{{Citation
| paradigms = [[Programming paradigm#Multi-paradigm|Multi-paradigm]]: [[Functional programming|functional]], [[Imperative programming|imperative]], [[Modular programming|modular]], [[Object-oriented programming|object-oriented]]
|title = Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems: facebook/reason|date=2019-03-23
| family = [[ML (programming language)|ML]]: [[Caml]]: [[OCaml]]
|url = https://github.com/facebook/reason
|publisher = Facebook
|access-date = 2019-03-23
}}</ref>
| latest release version = 3.6.0
| latest release date = March 5, 2020
| designer = Jordan Walke
| released = {{Start date and age|title2016|05|16}}<ref>{{Cite web |url=https://github.com/facebook/reason |title=Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems: facebook/reason |date=2019-03-23 |website=GitHub |publisher=Facebook |access-date=2019-03-23}}</ref>
| website = {{URL|https://reasonml.github.io/}}
| latest release version = {{wikidata|property|edit|reference|P348}}
| license = [[MIT License]]
| latest release date = {{start date and age|{{wikidata|qualifier|mdy|P348|P577}}}}
| file_ext = .re, .rei
| license = [[MIT License|MIT]]
| file_extfile ext = .re, .rei
| website = {{URLurl|https://reasonml.github.io/}}
| influenced by = [[OCaml]], [[JavaScript]]
| influenced =
}}
 
'''Reason''', also known as '''ReasonML''', is a [[syntaxGeneral-purpose programming language|general-purpose]], [[High-level programming language|high-level]], [[Comparison of multi-paradigm programming languages|multi-paradigm]], [[Functional programming|functional]] and [[Object-oriented programming|object-oriented]] [[programming language]] and [[Syntax (programming languages)|syntax]] extension and [[toolchain]] for [[OCaml]] created by Jordan Walke, who also created the [[React (webJavaScript frameworklibrary)|React]] framework, at [[Facebook]].<ref>{{Cite web |url=http://2ality.com/2017/11/about-reasonml.html |title=What is ReasonML? |website=2ality |access-date=2019-03-23}}</ref><ref>{{Cite Reasonbook offers|last1=Rauschmayer a|first1=Axel syntax|date=2018 familiar|url=http://reasonmlhub.com/exploring-reasonml/ to|title=Exploring [[JavaScript]] programmers,ReasonML and [[Source-to-sourcefunctional programming compiler|transpiles]]publisher=ReasonML toHub OCaml. Statically typed|access-date=2024-05-14}}</ref> Reason (oruses OCaml)many codesyntax mayelements befrom compiled[[JavaScript]], compiles to dynamicallynative typedcode using OCaml's [[JavaScriptcompiler]] toolchain, and can compile to JavaScript using the ''ReScript'' compiler.<ref>{{Cite web |title=Overview {{!}}: ReScript Documentation |url=https://rescript-lang.org |access-date=2020-08-10 |website=rescript-lang.org |language=en}}</ref>
 
The Reason community officially provides ReasonReact as a solution for [[React (web framework)|React]] -based web applications.<ref>{{cite web |url=https://reasonml.github.io/reason-react/en/ |title=ReasonReact |website=[[GitHub]]}}</ref><ref>{{cite web |url=https://dev.to/iwilsonq/reasonml-with-react-hooks-tutorial-building-a-pomodoro-timer-57h0 |title=ReasonML with React Hooks Tutorial — Building a Pomodoro Timer |date=2019-04-15 |first=Ian |last=Wilson}}</ref>
 
== BuckleScript and ReScript<span class="anchor" id="BuckleScript"></span><span class="anchor" id="ReScript"></span> ==
 
Reason was originally compiled to JavaScript using the BuckleScript compiler,<ref>{{cite news |url=https://www.bloomberg.com/company/press/open-source-at-bloomberg-introducing-bucklescript/ |title=BuckleScript |newspaper=Bloomberg L.p.|access-date=2022-09-11}}</ref> which was created at [[Bloomberg L.P.]]
 
In 2020, the BuckleScript and Reason toolchain was rebranded to [[ReScript (programming language)|ReScript]], essentially creating a separate language that had different syntax from Reason and only compiled to JavaScript.<ref>{{cite web |url=https://rescript-lang.org/blog/bucklescript-is-rebranding |title=BuckleScript & Reason Rebranding |website=rescript-lang|access-date=2022-09-11}}</ref>
 
BuckleScript was forked to Melange<ref>{{Cite web |date=2023-06-02 |title=ANN: Melange 1.0 – compile OCaml / ReasonML to JavaScript |url=https://discuss.ocaml.org/t/ann-melange-1-0-compile-ocaml-reasonml-to-javascript/12305 |access-date=2024-05-24 |website=OCaml |language=en}}</ref> 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 message|error messaging]], and editor tooling.<ref>{{Cite web |title=What & Why · Reason |url=https://reasonml.github.io/docs/en/what-and-why |access-date=2025-02-08 |website=reasonml.github.io |language=en}}</ref> 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 style|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 statement|switch]] construct (instead of a match construct) and a reformatter for error messages.
 
== Example ==
<syntaxhighlight lang="reason">
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 ++ "."
};
</syntaxhighlight>
 
== See also ==
{{Portal|Free and open-source software}}
* [[Elm (programming language)|Elm]]: a– A functional language that uses an abstraction called ports to communicate with JavaScript
* [[PureScript]]: a– A strongly-typed, purely-functional programming language that compiles to JavaScript
 
== References ==
Line 29 ⟶ 56:
 
== External links ==
{{wikibooksWikibooks|OCaml}}
* [https://reasonml.github.io/ {{Official website]}}
* {{GitHub|reasonml|Reason Project Organisation}}
* [https://reasonml.github.io/reason-react/ ReasonReact]
 
{{Prog-lang-stubML programming}}
 
{{Programming languages}}
{{Authority control}}
 
[[Category:Cross-platform free software]]
[[Category:Extensible syntax programming languages]]
[[Category:Free compilers and interpretersopen source compilers]]
[[Category:Functional languages]]
[[Category:ML programming language family]]
[[Category:Object-oriented programming languages]]
[[Category:ML programming language family]]
[[Category:OCaml programming language family]]
[[Category:Pattern matching programming languages]]