Jump to content
Wikipedia The Free Encyclopedia

Reason (programming language)

From Wikipedia, the free encyclopedia
Syntax extension and toolchain for OCaml
Reason
Paradigms Multi-paradigm: functional, imperative, modular, object-oriented
FamilyML: Caml: OCaml
Designed by Jordan Walke
First appearedMay 16, 2016; 9 years ago (2016年05月16日)[1]
Stable release
3.17.0[2]  Edit this on Wikidata / August 3, 2025; 2 months ago (August 3, 2025)
License MIT
Filename extensions .re, .rei
Websitereasonml.github.io
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.[3] [4] 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.[5]

The Reason community officially provides ReasonReact as a solution for React-based web applications.[6]

BuckleScript and ReScript

[edit ]

Reason was originally compiled to JavaScript using the BuckleScript compiler,[7] 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.[8]

BuckleScript was forked to Melange[9] to continue to support compiling OCaml to JavaScript.

Differences from OCaml Syntax

[edit ]

While Reason compiles down to native code via OCaml's toolchain, it specifically differs in its syntax, error messaging, and editor tooling.[10] 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[11] —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 ]
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 ++ "."
 };

See also

[edit ]
  • 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 ]
  1. ^ "Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems: facebook/reason". GitHub. Facebook. 2019年03月23日. Retrieved 2019年03月23日.
  2. ^ "Release 3.17.0". 3 August 2025. Retrieved 14 August 2025.
  3. ^ "What is ReasonML?". 2ality. Retrieved 2019年03月23日.
  4. ^ Rauschmayer, Axel (2018). Exploring ReasonML and functional programming. ReasonML Hub. Retrieved 2024年05月14日.
  5. ^ "Overview: ReScript Documentation". rescript-lang.org. Retrieved 2020年08月10日.
  6. ^ "ReasonReact". GitHub .
  7. ^ "BuckleScript". Bloomberg L.p. Retrieved 2022年09月11日.
  8. ^ "BuckleScript & Reason Rebranding". rescript-lang. Retrieved 2022年09月11日.
  9. ^ "ANN: Melange 1.0 – compile OCaml / ReasonML to JavaScript". OCaml. 2023年06月02日. Retrieved 2024年05月24日.
  10. ^ "What & Why · Reason". reasonml.github.io. Retrieved 2025年02月08日.
  11. ^ "The OCaml Language - Parenthesized Expressions". ocaml.org. Retrieved 2025年09月30日.
[edit ]
Wikibooks has a book on the topic of: OCaml
ML programming
Software
Implementations,
dialects
Caml
Standard ML
Dependent ML
Programming tools
Theorem provers,
proof assistants
Community
Designers
  • Lennart Augustsson (Lazy ML)
  • Damien Doligez (OCaml)
  • Gérard Huet (Caml)
  • Xavier Leroy (Caml, OCaml)
  • Robin Milner (ML)
  • Don Sannella (Extended ML)
  • Don Syme (F#)
  • AltStyle によって変換されたページ (->オリジナル) /