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:
| Library | To… |
|---|---|
visu | visualize memory, recursive calls, trees and graphs (Basthon.Visu) |
graphviz | draw graphs described in DOT (Basthon.Graphviz) |
ocamlgraph | graphs and their algorithms (Graph module) |
zarith | big integers and rationals (Z and Q modules) |
containers, containers-data | priority queues, deques, dynamic arrays… |
yojson, csv | read 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.
