Reason Native
  • Docs
  • Help
  • GitHub

›Overview

Overview

  • Introduction
  • Native Basics
  • Getting Started

Rely

  • Introduction
  • Quickstart
  • Guides

    • Setup and Teardown
    • Mock Functions

    API Reference

    • Basic API
    • Expect
  • Advanced

Console

  • Introduction
  • Quickstart
  • API

Pastel

  • Introduction
  • Quickstart
  • API
  • Console

Refmterr

  • Introduction
  • Quickstart

File Context Printer

  • Introduction
  • Quickstart
  • API

Getting Started

Install Esy

We recommend using Esy as your package manager in native Reason projects. Esy is a native, npm-esque package manager with built-in dependency isolation and fast, incremental builds.

The easiest way to install Esy is with npm:

npm install -g esy

Create a fresh project

First, clone a copy of the esy-ocaml/hello-reason project:

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

Then, run esy to install relevant dependencies and build your app:

esy

Run your first app

Run

esy x Hello.exe # runs Hello.exe

If everything went as expected, you should see the following output:

Running Test Program:
Hello, World!

Believe it or not, you're already using two Reason Native packages!

Pastel

Open up lib/Util.re and you might see something interesting:

/* lib/Util.re */
let hello = () =>
  Pastel.(
    <Pastel>
      <Pastel color=Red> "Hello" </Pastel>
      ", "
      <Pastel color=Green> "World" </Pastel>
      "!"
    </Pastel>
  );

Pastel is a React-like text formatting library for the terminal; one of its core features is the ability to format console text with ANSI Escape Codes.

Let's try making Hello yellow:

/* lib/Util.re */
/* ... */
    <Pastel>
      <Pastel color=Yellow> "Hello" </Pastel>
      ", "
/* ... */

Run esy build to rebuild your app, and run esy x Hello.exe to see your changes:

Running Test Program:
Hello, World!

Console

Similarly, let's take a look at bin/Hello.re:

/* bin/Hello.re */
Console.log("Running Test Program:");
let () = print_endline(Lib.Util.hello());

The Console package allows you to log nearly anything without having to define any printers. Let's try logging a nested tuple:

/* bin/Hello.re */
Console.log((1, (2, 3)));
let () = print_endline(Lib.Util.hello());

Running esy build && esy x Hello.exe should produce the following:

{1, {2, 3}}
Hello, World!
← Native BasicsIntroduction →
  • Install Esy
  • Create a fresh project
  • Run your first app
    • Pastel
    • Console
Reason Native
Projects
RelyConsolePastelRefmterrFile Context Printer
More
GitHubStar
Facebook Open Source
Copyright © 2021 Facebook Inc.