hn.today

Arrows to arrows, categories to queries (2025)

reasonablypolymorphic.com55 points2 comments
Screenshot of Arrows to arrows, categories to queries (2025)

Catlang is a small programming language that compiles programs into a single SQL query for PostgreSQL to execute. It is not designed as a new way to write database queries: SQL is an intentionally awkward compilation target for testing the language’s real feature, an intermediate representation built from abstract category-theory concepts. The central idea is to translate programs expressed with categorical arrows into relational operations that SQL can perform.

A demonstration defines a function that returns 100 for any integer input, using a loop-like construct rather than simply returning a constant. The generated SQL is enormous, with nested SELECTs, joins, unions, and recursive-query machinery that encode the program’s control flow and values. Its size makes the mismatch between a concise program and its database representation conspicuous, while also showing that a loop can be expressed through a query. The example frames Catlang as an experiment in mapping arrows and categorical structure to queries, not as a claim that SQL is a sensible or efficient target for general-purpose programming. The project’s appeal lies in seeing how far a mathematically abstract intermediate language can be lowered into the concrete operations of a relational database.

Read on reasonablypolymorphic.com2 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.