This repository contains an example of a library written in ocaml/reason for both javascript (through bucklescript) and native (through the ocaml compiler).
The shared
directory contains the core of the library, available in
both modes. js
and native
contain the part specific to one
implementation of the library.
The library is composed of 3 modules:
Date
, which has an implementation per platform and can have a different interface per platform.Tomorrow
, which has one implementation shared for both platforms.Yesterday
, which has a signature shared by both platforms, but an implementation per platform.
There is companion blog post giving more details on how to create this kind of library step by step.
For bucklescript:
yarn
For native:
- install esy
- then run
esy install
It can work with opam, but we use esy in this example as it is easier to understand for people from the javascript world.
For bucklescript:
yarn bsb -make-world
For native
esy dune build @all
The commands are wrapped in a Makefile and can be called with make js
and make native
.