Reason (programming language)
| Reason | |
|---|---|
| File:Reason-logo.svg | |
| Paradigms | Multi-paradigm: functional, imperative, modular, object-oriented |
| Family | ML: Caml: OCaml |
| Designed by | Jordan Walke |
| First appeared | May 16, 2016[1] |
| 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.[2][3] Reason uses many syntax elements from JavaScript, compiles to native code using OCaml's compiler toolchain, and can compile to JavaScript using the Melange compiler.[4]
The Reason community officially provides ReasonReact as a solution for React-based web applications.[5]
Differences from OCaml Syntax
[edit | edit source]While Reason compiles down to native code via OCaml's toolchain, it specifically differs in its syntax, error messaging, and editor tooling.[6] This allows Reason to provide an experience more similar to JavaScript or TypeScript for developers, which some may be more familiar with.
While OCaml primarily uses parentheses or begin/end keywords to delimit blocks[7]—with nothing separating declarations—Reason tends to use curly braces to delimit blocks and semicolons for separating declarations. Like JavaScript, Reason also defines functions via arrow-like syntax rather than OCaml's fun keyword. Other notable differences include naming the pattern matching keyword switch (instead of match), and reformatting error messages to be more familiar to JavaScript programmers.
Example
[edit | edit source]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 ++ "."
};
BuckleScript and ReScript
[edit | edit source]Reason was originally compiled to JavaScript using the BuckleScript compiler,[8] 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.[9]
BuckleScript was forked to Melange[10] to continue to support compiling OCaml to JavaScript.
See also
[edit | edit source]Lua error in mw.title.lua at line 392: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').
- Elm – 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
[edit | edit source]- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
External links
[edit | edit source]- Lua error in Module:Official_website at line 94: attempt to index field 'wikibase' (a nil value).
- Reason Project Organisation on GitHub
- Melange documentation site
- ReasonReact
Lua error in Module:Authority_control at line 153: attempt to index field 'wikibase' (a nil value).
- 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