Reason
  • Docs
  • Try
  • API
  • Community
  • Blog
  • Languages iconDeutsch
    • 日本語
    • English
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • Українська
    • 中文
    • 繁體中文
    • Beim Übersetzen helfen
  • GitHub

›Setup

Intro

  • What & Why

Setup

  • Installation
  • Editor Plugins

Language Basics

  • Overview
  • Let Bindings
  • Primitives
  • Basic Structures
  • Types
  • Records
  • Variants
  • Options and nullability
  • Functions
  • Recursion
  • Destructuring
  • Pattern Matching
  • Mutable Bindings
  • Loops
  • Modules

Advanced Features

  • JSX
  • External
  • Exception
  • Object

JavaScript

  • Interop
  • Syntax Cheatsheet
  • Pipe First
  • Promise
  • Libraries
  • Converting from JS

Extra

  • Frequently Asked Questions
  • Extra Goodies
Translate

Installation

Important: If you are looking for ReScript (formerly BuckleScript) installation instructions, please refer to the ReScript website.

Reason comes with its own "npm like" package manager called esy:

npm install -g esy

To create your first Reason native CLI program, run the following commands:

git clone https://github.com/esy-ocaml/hello-reason.git
cd hello-reason

# Install all dependencies (might take a while in the first run)
esy 

# Compile and run Hello.exe
esy x Hello

Reason native development is essentially OCaml development. From here on, you want to read up following websites to get to understand the ecosystem:

  • esy: The esy package manager is designed to manage your npm and opam dependencies and efficiently caches & sandboxes your project compiler and dependencies. Check out the esy website to find out how to install dependencies, setting up package resolutions, and executing compiled programs.
  • opam: The opam package index lists all available packages available in the OCaml ecosystem
  • dune: dune is the official build system in the OCaml ecosystem. Check out the manual for more details on how to set up your project.

All your packages are managed in your package.json file. Usually you will find a dune file in each source code directory (such as bin/ and lib/) for all the build system settings as well.

Some esy Tips

Adding dependencies:

To add Reason / OCaml packages that happen to be hosted on npm, run esy add npm-package-name.

esy add refmterr

Opam integration:

esy treats the npm scope @opam specially. esy will install any package name with the @opam scope directly from opam. This is the only scope with special meaning. All other package names are assumed to be hosted on npm.

esy add @opam/bos

Advanced esy configuration:

See the configuration section from the complete esy docs.

Compiling to JavaScript

Reason + OCaml both leverage the js_of_ocaml (JSOO) compiler to compile from bytecode to JavaScript.

To get started with Reason + esy + JSOO, check out this hello-jsoo-esy template:

git clone https://github.com/jchavarri/hello-jsoo-esy.git
cd hello-jsoo-esy
esy

npm install
npm run webpack

What's Next?

After you have successfully compiled your first example, it's time to set up your editor to get access to all the nice features such as auto-completion. Later on you can check out the language basics to get a basic understanding of all the Reason language constructs.

← What & WhyEditor Plugins →
  • Compiling to JavaScript
  • What's Next?