Available · Part II · 2026 · KC Sivaramakrishnan

A programmatic diagramming library for OCaml

Programmatic diagramming tools let developers, educators and researchers turn structured data (like trees, graphs, ASTs, neural networks, symbolic terms, ...) into clear pictures without reaching for a full interactive visualisation stack. Shriram Krishnamurthi's group at Brown recently released sPyTial, a Python library in which diagram layout is expressed as a set of constraints (left children stay left, top-down layering is preserved, etc.) and solved on demand.

This means that when the user drags a node around in a live rendering, the invariants of the underlying structure snap back into place, rather than devolving into the tangled force-graph messes that d3 typically produces.

This project would design and implement a lightweight diagramming library for OCaml. The goal is a composable DSL for describing structured data and the spatial invariants that should hold over it, along with a constraint solver that realises a layout and a rendering backend (SVG for static output, and ideally a browser target via js_of_ocaml or wasm_of_ocaml for interactive use).

Interesting design questions for the student to explore:

  • How to express layout constraints idiomatically in OCaml's type system; e.g. GADTs for well-typed diagram descriptions, (and for an ambitious student) modes and locality from OxCaml Labs for zero-allocation solver inner loops, or a simpler combinator library in the tradition of diagrams in Haskell.
  • Which constraint solver to use (an off-the-shelf SMT backend, a bespoke incremental solver, or something like Cassowary) and how to keep interactive dragging responsive on large structures.
  • Whether the library can double as a teaching tool for OCaml data structures, as sPyTial is used at Brown, by rendering the state of algorithms like red-black tree insertion or AST transformations in real time.
  • How to work with language features in OCaml like functors or other higher order type definitions, which need to be propagated into values so they can be rendered but with extra hints from the type structures.

A successful project would produce a reusable library with a handful of compelling demo diagrams (binary search trees, lambda-calculus ASTs, and perhaps a small embedding from TESSERA, along with benchmarks comparing layout quality and interactive performance against the Python original.