
Programming with Categories - kercker
http://brendanfong.com/programmingcats.html
======
yearoflinux
As someone who respects functional programming (because it removes geniuses
from competing in my space) here's a nice video
[https://www.youtube.com/watch?v=ADqLBc1vFwI](https://www.youtube.com/watch?v=ADqLBc1vFwI)

What is the beautiful monospace font in the pdf here
[http://brendanfong.com/programmingcats_files/cats4progs-
DRAF...](http://brendanfong.com/programmingcats_files/cats4progs-DRAFT.pdf)?

~~~
mindcrime
> here's a nice video
> [https://www.youtube.com/watch?v=ADqLBc1vFwI](https://www.youtube.com/watch?v=ADqLBc1vFwI)

OMG. That might just be the funniest god-damned thing I've ever seen in my
life. Thanks for sharing that!

On a separate note: does anyone know where this footage is originally from?
Some WWII movie, I would guess?

~~~
Tainnor
[https://en.wikipedia.org/wiki/Downfall_(2004_film)](https://en.wikipedia.org/wiki/Downfall_\(2004_film\))

Probably one of the best "WWII movies" (it's really only about the final days
in the bunker) ever.

~~~
abrookewood
Just seconding that Downfall is brilliant. Totally off-topic now, but also
extremely good is Das Boot.

------
mncharity
When taught in January at MIT, a highlight was something I'd not seen
elsewhere: someone called it the "aftermath" (3-pun). After the one-hour
traditional-ish lecture (on video), the room was reserved for an additional
hour.

When previously taught, people would remain afterwards to ask questions,
discuss math, and chat. So this was an iterative-improvement formalization of
that.

People would gather in front of the blackboards in fluid discussion clusters.
Catalyzed by the three instructors and wizzy others, not all having to stay
for the entire hour, but drifting off as discussion died away. They could show
material they had pruned from the lecture, for want of time. Or got dropped as
they ran over. Alternate presentation approaches they had considered, before
selecting another. They could be much more interactive. One commented roughly
"If I was tutoring someone, I'd never present the material this way". It was a
delightful mix of catching the speaker after a talk to ask questions, a
professor's office hours, a math major's lounge, an after-talk social,
tutoring, an active-learning inverted classroom, hanging out with neighbors in
front of the hallway blackboard, chalk clattering and cellphones clicking to
snag key insights... It was very very nifty.

So, the book is nice. And lecture notes. And videos. But... the best part
isn't there. Perhaps the next iterative improvement is to capture the
aftermath on video, and share that too.

And as we look ahead, planning distance-learning and XR tools... maybe
something like this is a vision to aspire too. The insane ratio of expertise
to people learning is not something one can plausibly replicate in meatspace.
But as conversations in front a virtual blackboard gradually become
technically feasible, something like this might pay for the cost of it, with
transformative impact.

~~~
Meandering
This is the most valuable part of the in person learning experience. Free form
discussion and building intellectual context around a subject. I experienced
this in a community college environment. This should be encouraged in any
learning environment.

~~~
quickthrower2
This is what I sort of dreamed university would be like. But alas it wasn’t.
Just lectures and students doing the minimum to get through the week and hit
the bars.

------
sideeffffect
If you're interested in how Category theory and Algebra can inform the design
of software, have a look at ZIO Prelude.

[https://github.com/zio/zio-prelude](https://github.com/zio/zio-prelude)

It's a brand new library for Scala that contains reusable mathematical
structures. Still based on algebra and category theory, but it expresses them
more or less differently than how they've been expressed in Haskell (and
similar languages). For example, unlike Haskell (and Scala's own cats and
ScalaZ), it doesn't present the "traditional" Functor -> Applicative -> Monad
hierarchy. Instead, it presents the mathematical concepts in a more orthogonal
and composable way.

One example out of many, you don't have a Monad. You have two distinct
structures:

* Covariant functor, with typical map operation `map[A, B](f: A => B): F[A] => F[B]`

* IdentityFlatten which has a flatten operation `flatten[A](ffa: F[F[A]]): F[A]` and an identity element `any: F[Any]`

When combined together (Scala has intersection types), you get something
equivalent to the traditional Monad.

The project is in its infancy, so it may still change significantly, though.
Look here for more detailed explanation:

[https://www.slideshare.net/jdegoes/refactoring-functional-
ty...](https://www.slideshare.net/jdegoes/refactoring-functional-type-classes)

[https://www.youtube.com/watch?v=OwmHgL9F_9Q](https://www.youtube.com/watch?v=OwmHgL9F_9Q)

~~~
tsss
Are there any useful types that have `flatten` but not `map` or `contraMap`?

~~~
sideeffffect
If I understood John's motivation from the video, it's that this enables the
Flatten structure to be inspectable, because the innards are not hidden behind
an opaque closure (A => F[B]), as is the case in regular Monad.

Btw, this is a problem that the "Selective applicative functor" too aims to
alleviate.

You can read more about the inspectability problem (and Selective) at
[http://eed3si9n.com/selective-functor-in-sbt](http://eed3si9n.com/selective-
functor-in-sbt)

The context there is sbt, which is a build tool, but I'm sure the
inspectability plays role in many other areas. Note, how he contrasts
"Applicative composition" and "Monadic composition".

------
linkdd
I've read a lot about Category Theory, and I'm amazed at the abstraction level
that lets you compose with different mathematical domains (geometry, topology,
arithmetic, sets, ...).

And yet, the current mathematics relies heavily on the ZFC set theory. Why is
that ? (Is that assumption even correct ?)

From what I've learned so far, the set theory suffers from Russel's Paradox[0]
(does the set of all sets that does not contain itself, contains itself ?).
That's what motivated the formalization of Type Theory and the invention of
Type Systems in programming languages.

According to wikipedia[1], __some __type theories can serve as an alternative
to set theory __as a foundation of mathematics __.

It seems to me that the Category Theory fits the description. So why don't we
see a huge "adoption" in math fields ?

Thank you in advance for your clarifications :)

[0] -
[https://en.wikipedia.org/wiki/Russell%27s_paradox](https://en.wikipedia.org/wiki/Russell%27s_paradox)
[1] -
[https://en.wikipedia.org/wiki/Type_theory](https://en.wikipedia.org/wiki/Type_theory)

~~~
johncolanduoni
ZFC does not suffer from Russel’s paradox, since it doesn’t allow a “set of
all sets”. If it did, the search for new foundations would be much more
widespread. New foundations are usually only considered seriously once they
can be shown to be relatively consistent with ZFC or the slightly stronger but
still uncontreversial TG set theory.

There are people working on categorical foundations, but the main reason for
lack of broader popularity or drive is that most mathematicians don’t do work
that is “foundational” in that sense. For example, if you’re an analyst, you
generally don’t care exactly how your real numbers are built (dedekind cuts,
Cauchy sequences, etc.). You only care that they satisfy a certain set of
properties, you can define functions between them, and that’s about it. Most
mathematical reasoning at this level is insensitive to differences in proposed
foundations, except “constructive” foundations that don’t have the law of
excluded middle (that are unpopular since they make many proofs harder and
some impossible).

What is very popular in mathematics is using category theory at a high level;
basically every field uses its concepts and notation to some degree at this
point. New foundations are only really relevant to this program in that they
may make automated proof checking easier, which is also not a widespread
practice in mathematics.

~~~
spekcular
It is not true that "basically every field uses its concepts and notation to
some degree at this point." In particular this is false for mainstream
combinatorics, PDE, and probability theory, to give a few examples.

In fact, I would suggest that most mathematicians don't care about category
theory at all.

~~~
bitdizzy
This all hinges on "mainstream". For example, in combinatorics, combinatorial
species are a vast organization of the all-important concept of _generating
function_. They were developed by category theorists and are most tidily
organized along categorical lines. If you don't think this is close enough to
mainstream, I can't dispute that. It's a value judgment.

There is often an undercurrent of category theory within a subject that maybe
most people are not privy to. Anything to do with sheaves or cohomology (which
I know factors into some approaches to PDEs) are using categorical ideas.

Every generation, it seems, has some contingent of serious mathematicians who
consider category theory marginal in their field of interest. But every
generation, that contingent grows smaller as more mathematics as practiced is
brought into the fold. Maybe they're coming for you next :)

~~~
spekcular
Respectfully, I disagree. The question of what's mainstream and valued by the
community is empirical and can be answered by looking at what's published in
the leading combinatorics journals. And anyone can check those out and see
that categories are basically absent. So as a sociological fact, I maintain
it's far from the mainstream.

Whether combinatorialists _ought_ to elevate certain work is of course of a
question of value, but it's also a different question.

Also, in no way are sheaves or (co)homology essentially category-theoretic
ideas. It's possible to develop and use these ideas without mentioning
categories at all (and e.g. Hatcher's introductory textbook does just this,
although he mentions in an appendix the categorical perspective later). In
general I think it's good to remember that homological algebra and category
theory are not the same subject. Sure, I can develop a theory of chain
complexes over an arbitrary abelian category, but most of the time you just
need Hom and Tor over a ring. (Again, see Hatcher.)

Finally, I'm not sure there has been a serious uptake in category theory in
the mainstream of some field of mathematics since, I don't know, at least 50
years ago? We've understood for a while now what it's good and not good for.
This hasn't stopped people from trying to inject it in fields where it doesn't
do any good (e.g. probability), but for that reason those attempts are mostly
ignored.

~~~
bitdizzy
> Respectfully, I disagree. The question of what's mainstream and valued by
> the community is empirical and can be answered by looking at what's
> published in the leading combinatorics journals. And anyone can check those
> out and see that categories are basically absent. So as a sociological fact,
> I maintain it's far from the mainstream.

I think it is also a reasonable interpretation to take "mainstream" as
"pertaining to the main subject matter of the field". Anyway, I think it is
the case that the mainstream of combinatorics or probability is yet so big
that a particular researcher or even group of researchers can be comfortably
in the mainstream and yet have never cared for or even heard of some other
line of research that is also mainstream.

The founding paper of combinatorial species [1] has hundreds of citations
including many in what I gather are top journals in combinatorics, and even
some in the Annals of Probability. So, what are we to make of that? Some
people who are serious enough about combinatorics or probability to get
published in serious journals have read, perhaps understood, and maybe even
taken seriously some of these categorical ideas?

In any case, I respect your viewpoint. In my youth I was a bit category-crazy,
trying to use it to organize _all_ of my mathematical knowledge. I'm much more
prudent about it these days but I'm still an optimist that we will find more
unifying ideas in mathematics through it.

[1]
[https://www.sciencedirect.com/science/article/pii/0001870881...](https://www.sciencedirect.com/science/article/pii/0001870881900529)

~~~
spekcular
It may the case that combinatorics is large, with mathematicians focused on
their own particular sub-specialities, but I still don't believe category
theory can properly be construed as "mainstream combinatorics" in any real
sense.

Regarding your claim about that paper being cited by papers in top journals, I
checked the first five pages of citations in Google Scholar for combinatorics
and probability journal papers.

It's cited once in an offhand way in the concluding discussion of "The Cycle
Structure of Random Permutations." No categorical concepts are used there.
Ditto for the "Independent process approximations" paper (except now cited in
the introduction). Another one-sentence mention in the context of background
literature appears in "Tree-valued Markov chains derived from Galton-Watson
processes." Same for "A Combinatorial Proof of the Multivariable Lagrange
Inversion Formula" and "Bijections for Cayley Trees, Spanning Trees, and Their
g-Analogues."

There's a one-sentence mention with actual (slight) mathematical content in
"Limit Distributions and Random Trees Derived from the Birthday Problem with
Unequal Probabilities." But you don't need categories to prove the bijection
they're referring to, from what I understand.

In none of these instances is the work used in a substantive fashion, and
unless I missed something no paper features the word "category." It's getting
cited because authors have a duty to survey any potentially related background
literature.

(On page 6 I found "Commutative combinatorial Hopf algebras," which does use a
functor form that paper. It was published in a journal that is decent, but
very far from the top.)

So, I think we can reject the notion that Joyal's paper has seriously
influenced the fields of combinatorics or probability.

I'm sorry to harp on this, but I see claims like yours about the importance of
category theory thrown around a lot on here, and often I feel that they're
clearly wrong. So I thought it would be good to provide some details this time
around.

~~~
bitdizzy
I should have demonstrated my picks. I didn't just look for citation but also
looked for at least some nontrivial review of the results of the paper^.

I pick these two papers. The first is literally about adjunctions pertaining
to combinatorial species whereas the second devotes an entire section to
reviewing the theory and stating results that it uses in a way that I don't
really understand. I'm going to read the first paper though because it's
relevant to my interests :)

Rajan. The adjoints to the derivative functor on species

[https://www.sciencedirect.com/science/article/pii/0097316593...](https://www.sciencedirect.com/science/article/pii/009731659390073H)

Panagiotou, Konstantinos; Stufler, Benedikt; Weller, Kerstin. Scaling limits
of random graphs from subcritical classes.

[https://projecteuclid.org/euclid.aop/1474462098](https://projecteuclid.org/euclid.aop/1474462098)

The fact that I have to go rummaging around for these examples kind of proves
your point, doesn't it? I don't think category theory will lead to any
fantastic new results in the fields we're discussing, but the bar is quite low
for it to be useful as an organizational tool.

^ I searched for the word functor of course! :)

~~~
spekcular
OK. The first paper is indeed literally about species and in a good but not
top journal. But it's not connected to the mainstream of combinatorics in any
way, in the sense that if you aren't _a priori_ interested in species, there's
no reason to be interested in the paper.

The second paper is interesting because it's in an excellent journal and about
a problem not obviously connected with species. So I agree that it counts as a
good example for your case. I also agree with your conclusion – it's an
exception that proves the rule, so to speak. Most probabilists have no need
for category theory, and most AoP papers don't use categories. (I feel that
may literally be the only one?)

I also agree that, to the extent it's useful, it's useful as an organizing
principle and not "substantively." I suppose this explains why I feel it's
overhyped: mathematicians care about solving problems, and the insights that
solve the problems ultimately have to come from some problem-specific
observations.

------
mcalus3
"We will assume no background knowledge on behalf of the student, starting
from scratch on both the programming and mathematics."

This is a fantastic "side effect" of the fact that category theory isn't built
on any other mathematical knowledge. You don't even need even any arithmetics
for that.

~~~
spirographer
At a meta level, Category Theory requires some comfort with abstraction, which
really only comes with a mathematical education. So while it may stand apart
from much math, it relies on your strong mathematical foundations.

~~~
dkarl
As so many undergraduate math textbooks say, "No background is assumed beyond
sufficient mathematical maturity."

~~~
inopinatus
Tautological sufficiency/necessity relativities for an absolute measure are a
pet peeve:

“How much salt should I add?”

“Oh, not too much.”

Practically guarantees a withering glare from me.

~~~
dkarl
That's a really great analogy, actually. You can't tell a brand-new cook "salt
to taste," but you can tell a cook with an intermediate level of experience
"salt to taste" even if it's a recipe they've never made before. You can't
impart the experience in words, pictures, or symbols. You can't add a chapter
zero that gets them there. But the right kind of experience will get you there
pretty quickly.

I admit it's kind of frustrating that it can't be boiled down to a list of
discrete things you need to know, but if I had to explain the difference
between me before I had "sufficient mathematical maturity" and me after, I
would explain it in terms of habit and confidence and other squishy things
that aren't mathematical at all.

~~~
richthegeek
Giving a precise value for this doesn't work in any case. "Salt to taste" is
inherently qualitative.

Most pizza dough recipes quote around 5g of salt for 250g flour. Personally I
prefer double that amount, and this is the case with many recipes.

Perhaps specifically with salt there is an insane amount of paranoia about
blood pressure. In many ways it feels as irrational as Korean worries about
fan death.

On the other hand, giving a "5g of salt" value is a good starting point, to
avoid undersalting due to paranoia or oversalting due to inexperience.

~~~
dkarl
What they really need is someone to tell them to add less than they probably
need, then taste, add more, taste, add more, and expect to over-season and
under-season some dishes as they get experience. Salt quantities in recipes
have to be short, sometimes way short, so you're stuck learning the process
with or without the quantities. I've never seen this explained in a cookbook,
at least not in a way that made an impression on me.

Edit: A piece of advice that has stuck with me for a long time, long after I
forgot where it came from, is it's a mistake to look for the state in between
"not salty enough" and "too salty." That state doesn't really exist,
especially when you're feeling nervous! Instead you should look for the
overlap where you can perceive the dish as alternately "not salty enough" and
"too salty," like that ambiguous drawing that your brain can resolve to either
an old woman or a young woman[0]. That advice really works for me, but my
wife, who seasons like a pro, thinks it's nonsense, which I think illustrates
how subjective the process is and how it isn't information you can impart but
rather experience you have to guide someone toward.

[0] [https://en.wikipedia.org/wiki/My_Wife_and_My_Mother-in-
Law#/...](https://en.wikipedia.org/wiki/My_Wife_and_My_Mother-in-
Law#/media/File:My_Wife_and_My_Mother-in-Law.jpg)

------
iso8859-1
Videos of the lectures from last year:
[https://www.youtube.com/watch?v=NUBEB9QlNCM](https://www.youtube.com/watch?v=NUBEB9QlNCM)

~~~
nwallin
Here's the full playlist: [https://www.youtube.com/playlist?list=PLhgq-
BqyZ7i7MTGhUROZy...](https://www.youtube.com/playlist?list=PLhgq-
BqyZ7i7MTGhUROZy3BOICnVixETS)

------
max68
These guys wrote "An Invitation to Applied Category Theory." It's an awesome
book, and I'm super excited for these lectures.

------
gumby
For those who might not realize: IAP is the period between semesters at MIT,
roughly most of January. So this is is a quick, accessible introduction, not a
heavy semester-long slog.

------
hawkice
In my experience, Monad, Applicable, and Monoid are probably the only ones I'd
use in Haskell, and maybe none of them in languages without good inference and
general support.

Pretty wild ideas, though. Fair chance they'd be more confusing than using
more specifically named instances, but solid ideas where the class instance
documents that you're using the pattern, instead of describing the preferred
interface.

~~~
smabie
You've definitely used Functors or Semigroups as well, you just didn't realize
it.

~~~
tsimionescu
Here is my problem with these ideas in programming: if you recognize that some
common construct is in fact a semigroup or functor, does knowing this actually
buy you anything?

I suppose it might help sometimes when designing an abstraction, to guide you
to some nice properties, such as easy composition.

~~~
rotifer
While playing around with a problem at work involving Markov chains and graph
connectivity, I found it useful to know that I could write (in Java) a generic
method that performed "exponentiation by squaring" on semigroups.

So, in addition to being able to raise numbers to powers I could also use it
on matrices whose elements belonged to a semiring.

That is, I could use the same code on a matrix of doubles with "times" and
"plus" (for the Markov chains), as well as a matrix of booleans with "and" and
"or" (for the graph connectivity).

(Of course, I could have used special purpose libraries, but these were small
problems and it was fun. :)

------
aeontech
For a humorous use case of types, nothing has beat Aphyr's (of Jepsen fame)
"Typing the Technical Interview" here: [https://aphyr.com/posts/342-typing-
the-technical-interview](https://aphyr.com/posts/342-typing-the-technical-
interview)

If you haven't read it, take a minute...

------
random3
Wow, what a combo! I'd be interested in anything from each of the lecturers,
but all 3 at the same course, is amazing.

Category Theory could be the rosetta stone of many things(this is relevant
[https://arxiv.org/pdf/0903.0340.pdf](https://arxiv.org/pdf/0903.0340.pdf)).

------
razster
What an odd coincidence that this was posted and on my YT subscribe page:
[https://www.youtube.com/watch?v=NUBEB9QlNCM](https://www.youtube.com/watch?v=NUBEB9QlNCM)
\- Just posting the video for others to see.

------
apkallum
David Spivak and other folks at Azimuth Forum[0] have been great at providing
high quality discussions on ideas in this course and others. Many thanks.

[0] [https://forum.azimuthproject.org](https://forum.azimuthproject.org)

~~~
read_if_gay_
Is this Spivak related to the author of the famous Calculus book?

~~~
dan-robertson
David and Michael Spivak are not related

------
LockAndLol
This doesn't work at all with HTTPS Everywhere. Just get a page about
DreamHost site not found.

------
Myrmornis
Will the course be taught live again and if so will those geographically
elsewhere be able to attend?

------
SJC_Hacker
Does it compile to WebAssembly VM? Any compilers on Android or iOS? Will it
work with Docker? Is it deployable on AWS or Azure?

------
mortdeus
the second i saw haskell i started saying eternally, "ABORT ABORT!"

You are going to have to revive jesus to come up with a functional language
that simplifies coding over a procedural one. Especially over an object
oriented one.

