Tablecloth

CircleCI Npm Opam

Tablecloth is an ergonomic, cross-platform, standard library for use with OCaml and Rescript. It provides an easy-to-use, comprehensive and performant standard library, that has the same API on all OCaml/Rescript platforms.

Tablecloth is alpha-quality software, and is pre-1.0. The API will change over time as we get more users. Caveat emptor.

Check out the website for our interactive API documentation.

See the CHANGELOG for list of changes in each release.

Installation

Rescript

Install via npm by:

npm install tablecloth-rescript

Then add to your bsconfig.json file:

"bs-dependencies" : ["tablecloth-rescript"]

OCaml native

Install via opam:

opam install tablecloth-native

Then add to your dune file:

(libraries (tablecloth-native ...))

Usage

The recommended way to use Tablecloth is with a top-level open at the beginning of a file.

This will ensure that all the built-in modules are replaced.

open Tablecloth

let () =
  String.toList "somestring"
  |> List.map ~f:Char.toCode
  |> List.map ~f:(fun x -> x+1)
  |> List.filterMap ~f:Char.fromCode
  |> String.fromList

Supported versions

Rescript

Tablecloth supports Rescript 9. Older versions of Tablecloth supported older versions of bs-platform.

Native

Tablecloth for native OCaml supports OCaml 4.08-4.10 and Base v0.12.2/v0.13.2. We are open to supporting other versions:

Development

When developing Tablecloth, you can test it against different versions of rescript, OCaml (native) and Base, using the following commands:

Design of Tablecloth

Dark uses multiple versions of OCaml on the frontend and backend:

We discovered that it was impossible to share code between the Rescript frontend and the native OCaml backend, as the types and standard libraries were very different:

Tablecloth's solution

Tablecloth solves this by providing an identical API for Rescript and OCaml. It wraps existing standard libraries on those platforms, and so is fast and memory efficient. It is draws inspiration from Elm's standard library, which is extremely well-designed and ergonomic.

Tablecloth provides separate libraries for OCaml native/js_of_ocaml and Rescript . The libraries have the same API, but different implementations, and are installed as different packages.

The APIs:

We also have design goals that are not yet achieved in the current version:

Contributing

Tablecloth is an ideal library to contribute to, even if you're new to OCaml or Rescript.

The maintainers are warm and friendly, and the project abides by a Code of Conduct.

There are many small tasks to be done - a small change to a single function can be extremely helpful.

Check out the dedicated guide on contributing for more.

Developing

If you are new to OCaml there are a few prerequisites you will need to get started:

Please refer to the Makefile for a complete list of supported actions. Here is a handful of useful, supported commands:

License

Tablecloth uses the MIT license. Some functions are based on Elm/core (BSD), and from the *.Extra packages in elm-community, which use a BSD license.

Authors

Written with the help of Dark.