# Programmer builds a language whose compiler outputs one giant SQL query

Original title: Arrows to arrows, categories to queries (2025)

> Hacker News story 50361107 · language: en · submitted 2026-11-04
> Web version: https://zeli.app/story/50361107
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 82 · by [firstbase](<https://news.ycombinator.com/user?id=firstbase>) · 💬 8
[original](<https://reasonablypolymorphic.com/blog/arrows-to-arrows/>) · [HN discussion](<https://news.ycombinator.com/item?id=50361107>)

## Summary

Sandy Maguire wrote catlang, a small programming language that compiles to a single monstrous SELECT statement in postgres. Its intermediate representation is built from abstract category theory constructs, each with simple algebraic semantics, so retargeting the compiler to new backends becomes straightforward. A sample function that returns 100 via a loop desugars into a dense unicode expression and then into SQL so deeply nested it's nearly unreadable.

## Key quote

> Why have I done this? Because I needed a funny compilation target to test out the actual features of the language, which is that its intermediary language is a bunch of abstract category theory nonsense.

## HN discussion (8 comments)

### [sleepyams](<https://news.ycombinator.com/item?id=50365146>)

> Nice, I've also been playing around with creating a programming language based on some concepts in category theory, but I've been focusing more on the concept of polynomial functors.  I know there is somewhat of a stigma against category theory on Hacker News for some reason, but it's cool to see people inspired to create new languages inspired by category theoretic ideas.
>
> It was cool to read about "co-choice", although I looked up that term and couldn't really find it used anywhere, do you have a source?  (Also I think there is a typo in the type signature in the code block in this section.  The codomain of `cochoiceHask` should be `b` right?)  The idea of building a loop from a function `Either a c -> Either b c` is very interesting.  It reminds me of some of the ideas in the book "Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory" by Joseph E. Stoy, which you should check out if you haven't.

### [yccs27](<https://news.ycombinator.com/item?id=50364967>)

> How does the use of arrows instead of functions actually help here? If you have a terminal object aka unit type `()`, then arrows `() ~> a` are equivalent to elements of `a`.

### [skavi](<https://news.ycombinator.com/item?id=50362172>)

> bold to lead with an example that makes no sense at all.

---

## Cite

- Page: https://zeli.app/story/50361107
- Date: 2026-11-04
- Source: reasonablypolymorphic.com (https://reasonablypolymorphic.com/blog/arrows-to-arrows/)
- Hacker News: https://news.ycombinator.com/item?id=50361107

## Other languages

- zh: https://zeli.app/zh/story/50361107 · markdown: https://zeli.app/zh/story/50361107.md
- ja: https://zeli.app/ja/story/50361107 · markdown: https://zeli.app/ja/story/50361107.md
- ko: https://zeli.app/ko/story/50361107 · markdown: https://zeli.app/ko/story/50361107.md
- de: https://zeli.app/de/story/50361107 · markdown: https://zeli.app/de/story/50361107.md
- es: https://zeli.app/es/story/50361107 · markdown: https://zeli.app/es/story/50361107.md
- ru: https://zeli.app/ru/story/50361107 · markdown: https://zeli.app/ru/story/50361107.md
