ArticleslgStudy

computer science

Reason (programming language)

Reason (programming language) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Reason (programming language) rather than just read about it. In short: Reason, also known as ReasonML, is a programming language and toolchain that is part of the OCaml programming language ecosystem. 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.

Reason (programming language) — main illustration
Reason (programming language) — illustration

Key takeaways

  • Reason (programming language) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Reason (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Reason (programming language) from memory before moving on to harder problems.

Reference excerpt

Reason, also known as ReasonML, is a programming language and toolchain that is part of the OCaml programming language ecosystem. 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.

Language characteristics Since Reason is an alternate syntax to OCaml, they share the same characteristics. Both languages are general-purpose, functional and object-oriented. While Reason compiles down to native code via OCaml's toolchain, it specifically differs in its syntax, error messaging, and editor tooling. This allows Reason to provide an experience more similar to JavaScript or TypeScript for developers. Reason’s syntax is more similar to JavaScript and other C-style languages than to OCaml. For example, Reason tends to use curly braces to delimit blocks and semicolons for separating statements, while OCaml primarily uses parentheses or begin/end keywords to delimit blocks, with nothing separating declarations. Reason also defines functions via an arrow-like syntax (rather than OCaml's fun keyword), and calling a function requires parentheses around its arguments. Other notable differences include naming the pattern matching keyword switch (instead of match), and reformatting error messages to be more familiar to JavaScript programmers. The Reason community officially provides ReasonReact as a solution for web applications based on the React framework.

Example

History Jordan Walke, creator of the React web framework, first released Reason in 2016 while employed at Facebook. In the same year, Bloomberg L.P. introduced BuckleScript, a compiler which compiled OCaml to JavaScript. As both projects were influenced by JavaScript, Reason and BuckleScript soon became an integrated toolchain, allowing Reason to target JavaScript. However, the Reason team and the BuckleScript team had different priorities. The Reason team wanted to maintain compatibility with the OCaml ecosystem, while the BuckleScript team wanted to be able to change the syntax to give the best developer experience to JavaScript programmers. In 2020, BuckleScript introduced a new syntax that started to diverge from Reason. A month later, the BuckleScript team rebranded its toolchain to ReScript, to focus solely on the JavaScript ecosystem and essentially becoming its own language, distinct from Reason. To maintain the ability for Reason to target JavaScript, António Monteiro forked a version of BuckleScript before it was rebranded as ReScript, and changed it to bring it closer to the OCaml ecosystem. The fork, named Melange, released its first stable version in 2023.

See also

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

External links

Official website Reason Project Organisation on GitHub Melange documentation site ReasonReact

Illustrations

Reason (programming language) illustration

Worked examples

Example 1 — a first encounter with Reason (programming language)

Start with the simplest possible case. Write down what Reason (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Reason (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Reason (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Reason (programming language)

In research
Reason (programming language) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Reason (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Reason (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cross-platform free software, Extensible syntax programming languages, Free and open source compilers, so understanding it makes those chapters shorter.
In everyday life
Look for Reason (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Reason (programming language)” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Reason (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Reason (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Reason (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Reason (programming language) in simple terms?

Reason, also known as ReasonML, is a programming language and toolchain that is part of the OCaml programming language ecosystem. 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.

Why does Reason (programming language) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Reason (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Reason (programming language).

Tags

  • Cross-platform free software
  • Extensible syntax programming languages
  • Free and open source compilers
  • Functional languages
  • High-level programming languages
  • ML programming language family
  • OCaml programming language family
  • Object-oriented programming languages
  • Pattern matching programming languages
  • Programming languages created in 2016
  • Software using the MIT license
  • Statically typed programming languages

Keep exploring