# A programmatic diagramming library for OCaml

*2026-04-01 — idea*


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](https://cs.brown.edu/~sk/)'s group at Brown recently
released [sPyTial](https://pypi.org/project/spytial-diagramming/), 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](https://ocsigen.org/js_of_ocaml)
or [wasm\_of\_ocaml](https://ocaml.org/manual/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](https://anil.recoil.org/projects/oxcaml)
  for zero-allocation solver inner loops, or a simpler combinator library in
  the tradition of [diagrams](https://diagrams.github.io/) 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](https://anil.recoil.org/projects/tessera), along with
benchmarks comparing layout quality and interactive performance against the
Python original.

## Related Reading

- [sPyTial diagramming library](https://pypi.org/project/spytial-diagramming/)
- [Paper (to appear at PLDI 2026)](https://www.siddharthaprasad.com/unpublished/ptkns-spytial.pdf)
- [Diagrams for Haskell](https://diagrams.github.io/)
- [Cassowary constraint solver](https://overconstrained.io/)
- [The FP Launchpad takes off at IIT Madras](https://anil.recoil.org/notes/fpl-launch) — where the inspiration for this project came from
Status: Available
Level: PartII
Year: 2026
Project: OxCaml Labs
Supervisors: Anil Madhavapeddy, KC Sivaramakrishnan

## Related

- [The FP Launchpad takes off at IIT Madras](https://anil.recoil.org/notes/fpl-launch) (note, 2026-04-13)
- [OxCaml Labs](https://anil.recoil.org/projects/oxcaml) (project, 2025-01-01)
- [TESSERA, a pixelwise geospatial foundation model](https://anil.recoil.org/projects/tessera) (project, 2025-01-01)

---
Canonical: https://anil.recoil.org/ideas/spytial-ocaml-port
Type: idea
Tags: ocaml, graphics, dsl, fplaunchpad
