Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
Reason (programming language)
Syntax extension and toolchain for OCaml

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. 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.

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

We don't have any images related to Reason (programming language) yet.
We don't have any YouTube videos related to Reason (programming language) yet.
We don't have any PDF documents related to Reason (programming language) yet.
We don't have any Books related to Reason (programming language) yet.
We don't have any archived web articles related to Reason (programming language) yet.

BuckleScript and ReScript

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

BuckleScript was forked to Melange7 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 messaging, and editor tooling.8 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 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 construct (instead of a match construct) and a reformatter for error messages.

Example

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

  • Free and open-source software 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
Wikibooks has a book on the topic of: OCaml

References

  1. "What is ReasonML?". 2ality. Retrieved 2019-03-23. http://2ality.com/2017/11/about-reasonml.html

  2. Rauschmayer, Axel (2018). Exploring ReasonML and functional programming. ReasonML Hub. Retrieved 2024-05-14. http://reasonmlhub.com/exploring-reasonml/

  3. "Overview: ReScript Documentation". rescript-lang.org. Retrieved 2020-08-10. https://rescript-lang.org

  4. "ReasonReact". GitHub. https://reasonml.github.io/reason-react/en/

  5. "BuckleScript". Bloomberg L.p. Retrieved 2022-09-11. https://www.bloomberg.com/company/press/open-source-at-bloomberg-introducing-bucklescript/

  6. "BuckleScript & Reason Rebranding". rescript-lang. Retrieved 2022-09-11. https://rescript-lang.org/blog/bucklescript-is-rebranding

  7. "ANN: Melange 1.0 – compile OCaml / ReasonML to JavaScript". OCaml. 2023-06-02. Retrieved 2024-05-24. https://discuss.ocaml.org/t/ann-melange-1-0-compile-ocaml-reasonml-to-javascript/12305

  8. "What & Why · Reason". reasonml.github.io. Retrieved 2025-02-08. https://reasonml.github.io/docs/en/what-and-why