Context
Section titled “Context”dk's documentation and tests are themselves unified scripts (see the Unified Scripts guide). The .ml.u flavor embeds an OCaml REPL. The REPL works in the browser or on your computer; the cells below are the REPL running in a browser.
For dk you'll usually write Lua and value shell unified scripts (dk.u, dist-*/run.u) rather than .ml.u. This guide is for advanced users who want to build their own interactive documentation sites using dk-based tooling.
These cells run in your browser through an OCaml toplevel compiled to JavaScript with js_of_ocaml. Edit any block and press Run (or Ctrl/Cmd+Enter). The toplevel keeps state between blocks so later cells can use earlier definitions.
Arithmetic
Section titled “Arithmetic”let _ = 2 + 4Define a function
Section titled “Define a function”let rec fact n = if n <= 1 then 1 else n * fact (n - 1)Use it (state carries over)
Section titled “Use it (state carries over)”fact 5Lists and the standard library
Section titled “Lists and the standard library”List.map (fun x -> x * x) [ 1; 2; 3; 4; 5 ]