Content deleted Content added
Jerryobject (talk | contribs) WP:LINKs add. Small WP:COPYEDITs WP:EoS: clarify, WP:TERSE. |
Alexflatter (talk | contribs) No edit summary |
||
(9 intermediate revisions by 9 users not shown) | |||
Line 3:
| name = Reason
| logo = Reason-logo.svg
| logo_size = 200px
| paradigms = [[Programming paradigm#Multi-paradigm|Multi-paradigm]]: [[Functional programming|functional]], [[Imperative programming|imperative]], [[Modular programming|modular]], [[Object-oriented programming|object-oriented]]
| family = [[ML (programming language)|ML]]: [[Caml]]: [[OCaml]]
Line 11 ⟶ 12:
| license = [[MIT License|MIT]]
| file ext = .re, .rei
| website = {{
| influenced by = [[OCaml]], [[JavaScript]]
| influenced =
}}
'''Reason''', also known as '''ReasonML''', is a [[General-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 (JavaScript library)|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 book |last1=Rauschmayer |first1=Axel |date=2018 |url=http://reasonmlhub.com/exploring-reasonml/ |title=Exploring ReasonML and functional programming |publisher=ReasonML Hub |access-date=2024-05-14}}</ref> 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.<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-based web applications.<ref>{{cite web |url=https://reasonml.github.io/reason-react/en/ |title=ReasonReact |website=[[GitHub]]}}</ref>
Line 22 ⟶ 23:
== 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
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 ==
Line 48 ⟶ 67:
[[Category:Cross-platform free software]]
[[Category:Extensible syntax programming languages]]
[[Category:Free
[[Category:Functional languages]]
[[Category:Object-oriented programming languages]]
|