HeadlinesBriefing HeadlinesBriefing.com

Catlang: A Programming Language That Compiles to SQL

Hacker News •
×

The author has built catlang, a programming language whose compiler spits out one giant SQL SELECT statement. Running that query in Postgres produces the output of your program. It is not a new query language, but a full programming language that uses a funny compilation target to test out the language's actual features.

The intermediary language is abstract category theory nonsense expressed through arrow notation. The author demonstrates a count function that returns 100 regardless of input using a while-loop equivalent. After desugaring the source syntax, the code becomes a dense chain of algebraic symbols where each operator has specific semantics, such as piping the result of one operation into another.

Because every remaining symbol maps to simple algebraic rules, it becomes trivial to compile catlang to all sorts of weird compilation targets. The generated SQL is deeply nested and ungodly, relying on recursive CTEs and countless subqueries to execute ordinary program logic through systematic transformation.

The project shows that even obtuse, roundabout implementations can target SQL by transforming a categorical intermediate language into other domains, making the compiler both an academic exercise and a working proof of concept.

Source: Hacker News · Summarized by HeadlinesBriefing