161 points · by Schiphol · 3y ago · 93 comments
I'm open to having my mind changed. The one application that's come the closest is UMAP, [3] though the last time I checked, a few years ago, the jury was still out on whether the structure it produces in applied contexts like biology is spurious.
So what specific applications do you know of category theory to practical problems? For the purpose of this post "application" means used by someone in a production software setting to solve a problem not related to category theory. Someone who doesn't care about category theory should care about the problem being solved.
And, to be sure, category theory is fine an dandy in its applications to other areas of math, as a unifying language for homology and whatnot. I'm talking about the kind of claims category theory folks sometimes make like "category theory is ushering in a programming revolution and you need to learn it to stay relevant"
[1]: http://pmfpbook.org/
[2]: https://buttondown.email/j2kun/archive/whats-in-production/
His paper on Compiling to Categories [1] pitches programming language semantics as a cartesian closed category [2] allows for really cool stuff by mapping typical evaluation semantics to alternatives like building a computational graph visualization, a pretty printer, and imbuing the original program with automatic differentiation capabilities purely through the categorical interpretation of the same program. Essentially, if you can formulate a desired output of the program as a cartesian closed category, you can do it quite easily.
[1]: http://conal.net/papers/compiling-to-categories/
[2]: A cartesian category with is a category with an operation that lets you pair things together into a new object and get out the original parts with eliminators. Think construct a tuple and have the ability to get the first and second elements out of the tuple. A cartesian closed category adds in the ability to model (partial) function application to its arguments via "apply, curry, and uncurry." See https://en.wikipedia.org/wiki/Cartesian_closed_category
> used by someone in a production software setting to solve a problem not related to category theory
If this stuff or its derivative work is used in production in a mainstream compiler (GHC, perhaps?), then I would see it differently.
not sure if it went anywhere, but it even included self modifying fpga-like circuits iirc
There is a much simpler way of making this idea the foundation of pretty much everything though, see my report "Logic is Algebra" [1]. I've simplified matters further since then (for example, instead of the somewhat unfamiliar notation
(lambda x. D P[x])
you write now
lambda(D, x. P[x])
(maybe I should even go as far as just writing "lambda(D, x => P[x])", as that triggers probably even more neurons, especially in programmers).
lambda is here nothing special, just another operator you can introduce yourself, much like "forall", "exists", "sum", etc.
So category theory is, in my opinion, a pretty complicated framework to think in, pushing a certain view of things, and I think there is a more general, yet simpler framework. And I think that will be of use to everyone doing anything vaguely math related, and that certainly includes programmers.
[1] https://arxiv.org/abs/2304.00358
(The above report also includes lots of theory, and looks therefore more complicated than it really is. I am working on something new that leaves out the theory, uses more familiar syntax, and emphasises applications)
To say that learning a field is useful is to say that knowing these abstractions is useful.
Much of Haskell's "category theory" is a reuse of terms. Replace Monoid by Appendable, Monad by Composable, Functor by Runnable, etc. and most programming languages are "category theory".
This says little about whether knowing the field of category theory will be useful to programming. Indeed, I think there's a good argument to say Haskell programming is much harmed by it.
If its authors hadnt used their knowledge of category theory, but rather named the abstractions in more ordinary terms, the language would be more useful to more people.
I'm not sure an "Appendable" Int or IO type, or a "Runnable" / "Composable" List type is any less confusing to Joe Programmer. These descriptions do not articulate the same things implied by the Monoid, Functor, and Monad laws. Some of these aren't even correct (i.e. not all Functors are "Runnable", Monadic types do not necessarily compose directly, just via Kleisli composition).
> This says little about whether knowing the field of category theory will be useful to programming. Indeed, I think there's a good argument to say Haskell programming is much harmed by it.
> If its authors hadnt used their knowledge of category theory, but rather named the abstractions in more ordinary terms, the language would be more useful to more people.
I think this is really the least of Haskell's problems. Mystifying/poorly written monad tutorials and conflation with IO (or confusion about how IO works in the haskell runtime) is more responsible for confusing new programmers than the concept itself. I have no background in mathematics above undergrad calc 2 and I was able to understand them just fine.
The language would be just as useful, but it might _feel_ more approachable. Depending on the terms that replaced those it might be more confusing, or the opposite, than it is now.
I once watched John talk down to some sort of research electrical engineer at a conference because his diagrammatic calculus didn’t line up with John’s approach, when anyone with a lick of sense would want to understand why their approach didn’t suffice and how these changes addressed its shortcomings - this person was a subject matter expert and Baez condescended to him about his own field! I think his attitude has, unfortunately, rubbed off on a lot of the people in his orbit.
[1] https://arxiv.org/abs/2012.02113 [2] http://www.tac.mta.ca/tac/volumes/35/45/35-45.pdf
I can’t stress enough that Koditschek group are serious people who are using this stuff because it addresses problems they’ve been grappling with.
So your basic idea happens to be a Co-Variant Non-Infinitoid Subspace Category? Seriously who cares?
I aim to provide an example of applied category theory in computer science. Your understanding may differ due to the encompassing time frame, however, I ensure that even the most recent findings can rapidly transform into a practical programming concept.
The concept of 'monad' was initially introduced by Roger Godement in 1958, known as the 'standard construction'. The term 'monad' itself came into use later in 1967, credited to Jean Bénabou. The connection between monads and functional programming was first established in 1989 by computer scientist Eugenio Moggi. Moggi implemented monads in semantics to interpret the lambda calculus, a computational model that employs variable binding and substitution for function abstraction and application. The formal incorporation of monads into Haskell occurred in 1992 by Philip Wadler. Since then, monads are increasingly being integrated into mainstream programming languages, including JavaScript. For instance, JavaScript Promises can be viewed as a kind of monad. They encapsulate a value and allow its transformation with the .then method, which can be equated to the 'bind' operation in the realm of monads. Furthermore, a new Promise can be generated from any value using Promise.resolve, an operation analogous to the 'return' operation in monads. Promises have a very practical application and are used in programming by millions of developers every day.
The concept of a monad is one example that is well-understood; however, there are numerous other such ideas. One of these is the Functor, often referred to as "mappable" in mainstream programming languages. Research in this field is ongoing, with concepts like applicative functors, introduced by Conor McBride and Ross Paterson in 2008, already gaining popularity in languages such as Haskell.
This is what it seems category theorists tend to do: they build a framework, express existing ideas within that framework, and then claim that the existing work is an application of category theory.
I think that sort of retcon CAN be done. Many math topics like Fourier Analysis have taken practical results, built a math theory behind it, and then converted the entire field to the theory as standard domain knowledge. But the evidence that category theorists have done this, even in the realm of programming language APIs, seems slim.
Even if you agree that the APIs align and the people designing the API know their thing is secretly a monad, still calling that a "success" of category theory is rather weak. By comparison, just because something has addition, units, and inverses, it doesn't mean that group theory is being applied in a meaningful way. The nontrivial results about groups that DO seem to lead to "real" applications are related to the structure of particular groups, as used in cryptography. But I have seen little similar in the way of category theory. Porting concepts from category theory to Haskell is nice, maybe, but it's not clear to me that doing so isn't creating as many problems as its solving (e.g., lenses solve a problem that no other language has, and most Haskell programs seem to me to be completely unreadable by anyone except the author, despite me being no stranger to Haskell).
I think you missed one level of indirection in my argument. I'm not claiming that language designers employ Category Theory explicitly when designing new language features (although this is indeed the case with Haskell, PureScript, and similar languages). Rather, my argument is that Category Theory features typically debut in these purely functional languages and then you will see on the Wikipedia page of mainstream languages something like: “Influenced by Haskell” (e.g. Rust, +20 others) . Category Theory is very abstract by nature, so I think it is only natural that there is some kind of indirect step through e.g. Haskell where people can see it in action first, before such features land in mainstream programming languages. The language designers would then say, 'Well, I have been influenced by Haskell (and not by Category Theory)', although the concept behind it is truly based on CT.
Many programmers don't keep math books at their workstation. However, they constantly utilize mathematical concepts in their coding. Often, they refer to programming language tutorials where these mathematical ideas are already implemented, for example, in Python or C++. This is as opposed to learning the concepts directly from a book on Algebra, Geometry, or Trigonometry. However, that still qualifies as applied mathematics. Hence, I see no reason why it shouldn't count as applied CT if you borrow concepts from Haskell that are based on CT.
Indeed other languages don't have problems dealing with immutable collections since almost none have good immutable collections. All I can say is that, when working with other languages, I wish they did have that problem!
> most Haskell programs seem to me to be completely unreadable by anyone except the author
Interesting. That's the opposite of my experience. Haskell is pretty much the only language where I expect to be able to read code written by others ("others" including "myself a year ago").
Category theory is useful for thinking about X, X is super useful for modelling and designing Y.
X in {Petri net, relational algebra, feedback diagrams, type system, ... } and Y in {communication protocol, database, programming language, ... }
https://arxiv.org/pdf/1504.05625.pdf
That starts to make sense to me as a sort of generalized framework for Feynman-diagram-like things. Explains why particle physicists would be drawn to category theory as well.
Feels like there's still probably a hell of a lot of dots to connect there though.
I realize the question is somewhat strange and the answer depends on what people work on. Let's say it is not ML/AI.
I've enjoyed e.g. 'Calculus' by G. Simmons and Niven's 'The Mathematics of Choice' even though I didn't apply any of that at work.
We’re starting with categorical maps and then transporting that model into a type theory, while maintaining the semantics.
Effective patterns in doing so are “applied category theory”.
- Amazon Device Econ modeling platform, for econometrics
- Amazon Tax calculation platform, for things like VAT
But more broadly, that’s how you develop software: you’re theory building.
1. Develop language and rules in that language.
2. Give them semantic meaning in a diagram and set of example cases.
3. Develop a corresponding type theory for that.
4. Implement that synthetic domain theory in a general type theory — eg, a programming language.
You don’t have to know that it’s topos theory to do those steps, but each is better when you’re explicit about them — and knowing how to guide the first step to get good results at the last step is definitely applied topos theory.
I read a paper that claimed that the category of polynomial-like things ("Poly") was somehow useful for database migrations! Without a concrete example, that's just an absurd statement to make. If you don't explicitly connect the dots between SQL schemas and polynomials, then you're just hand-waving. It's the equivalent of: "I have a marvellous proof but alas it is too long to fit into this margin."
The paper I was referring to used the category Poly, and literally just stated that Poly could be used for database migrations without elaborating further.
Nice for theoretical work, bad for practical work.
Functor is useful though.
Here are some of the more interesting things it's good for:
1. The lambda calculus is the basis for most functional programming and for closures. The lambda calculus is also tightly linked to Cartesian closed categories. And a huge number of structures in math are either Cartesian closed categories, or at least topoi, which are closely related. This connection can be used to quickly sketch out designs for exotic programming languages.
2. Many simpler categorical ideas map cleanly to programming languages. Functors are parameterized types with `map` functions. Natural transformations correspond to certain kinds of tidy parameterized types. Even monads are basically just nested parameterized types that support `flatten`. And so on.
Now, most of this stuff is pretty shallow category theory. It's mostly definitions. But they're definitions that allow you to draw interesting connections between functional programming, parameterized types, and distant branches of math.
Used right, you can design some pretty unusual languages that fit together cleanly.
Probably true. However... I wouldn't take that comment too far. IMO if more programmers took interest in the subject, they might begin to see complexity/simplicity they didn't recognize before, and make different language choices, or take a different approach to compositionality.
Also it is very useful for theoretical computer scientists.
More like definitions of definitions :)
>I'm not a programmer. I apologize for this flaw.
> this is not a course on "categories in computer science". Nonetheless, because category theory is about understanding and organizing abstract data structures, everything I say will be relevant in some way to computing! Furthermore, several chapters in Seven Sketches explicitly discuss databases, and type systems, and other aspects of computer science.
I am beginning to think I'm doing this wrong, or simply don't know how to prioritize, a common modern problem of course.
It's impossible to cover everything about a topic in a short amount of time, but when you try, you at least develop a map of the terrain.
British English almost always adds 's for the singular possessive, even when the name ends in s, so Dickens's and St. James's.
However, American English often uses the plural possessive suffix ' for names ending in s. One Spanish name example I have seen is Bezos' for something of Jeff's (his billions, or his wives, I forget which).
But Baez' makes no sense to me on any side of the Atlantic.
I mean topology didn't have so many applications 100 years ago, but now that shits everywhere. Math is the ultimate r&d. It's literally the language of causality. Imho it can't not be useful.