Reason (programming language): Difference between revisions

Content deleted Content added
ReScript no longer works with Reason syntax, added notes about bucklescript fork to Melange.
No edit summary
 
(7 intermediate revisions by 7 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 = {{Official URLurl|https://reasonml.github.io/}}
| influenced by = [[OCaml]], [[JavaScript]]
| influenced =
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 webnews |url=https://www.bloomberg.com/company/press/open-source-at-bloomberg-introducing-bucklescript/ |title=BuckleScript |websitenewspaper=bloombergBloomberg 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 ==
Line 48 ⟶ 67:
[[Category:Cross-platform free software]]
[[Category:Extensible syntax programming languages]]
[[Category:Free compilers and interpretersopen source compilers]]
[[Category:Functional languages]]
[[Category:Object-oriented programming languages]]