← Wed, Nov 4 digest

Arrows to arrows, categories to queries (2025)

read article ↗ hn thread ↗

A developer built catlang, an experimental programming language that compiles category-theoretic arrows into a single massive recursive SQL query in PostgreSQL.

summary is enough The amusing core concept and architecture are fully explained in the text, saving you from parsing pages of generated SQL.

summary

An experimental programming language called catlang compiles functional code into category-theoretic arrows without variable names, targeting a single recursive PostgreSQL query. By stripping out names into a stack-based intermediate representation using products, coproducts, and a loop primitive, the compiler turns high-level logic into raw SQL. Running the resulting query executes loops entirely inside the database engine.

key points

  1. catlang eliminates variable names early by using a stack-based intermediate representation of category-theoretic arrows and projections.
  2. Loops are implemented using a custom categorical primitive called cochoice that maps iterative execution over coproducts.
  3. The compiler outputs a single recursive SQL query that executes a loop entirely inside PostgreSQL 17.

who should read it

Compiler engineers and functional programmers interested in esoteric compilation targets and category theory.

discussion positive

consensus

Readers appreciate the creative intersection of category theory and SQL, discussing connections to recursion schemes, polynomial functors, and symmetric monoidal categories.

pushback

A few commenters note the introductory code snippet is overly opaque and question whether arrows offer distinct advantages over standard functions.

best comment by sleepyams ↗

Yes, I think these are related-ish, also to traces on symmetric monoidal categories. If you have any algebraic/categorical formalization of wiring diagrams, this is essentially taking a block with inputs A and C and outputs B and C and connecting the C output to the C input with a self-loop.

It connects the custom loop operator to traces on symmetric monoidal categories and graphical feedback loops.

Generated by an LLM from the article and thread. Check the sources before relying on it.