Skip to content

OCaml libraries with #require ​

Basthon's OCaml kernel can now load libraries, with the #require directive of the OCaml toplevel, as you would with a library installed by opam:

ocaml
#require "zarith";;
Z.(~$2 ** 200);;

Libraries are only downloaded at the first #require, and are already compiled to JavaScript: they load almost instantly. Here are those available:

LibraryTo…
visuvisualize memory, recursive calls, trees and graphs (Basthon.Visu)
graphvizdraw graphs described in DOT (Basthon.Graphviz)
ocamlgraphgraphs and their algorithms (Graph module)
zarithbig integers and rationals (Z and Q modules)
containers, containers-datapriority queues, deques, dynamic arrays…
yojson, csvread and write JSON and CSV data

The libraries specific to Basthon are put in the Basthon module: after #require "visu", write for instance module Visu = Basthon.Visu. Basthon.help () lists them all. By the way, the Basthon module gains display_svg and display_html to show an SVG image or HTML.

Each one has its example notebook in the gallery, presented in the following posts.

See the gallery

Loading libraries and the help of the Basthon module