
Category Theory for the Sciences - 0xmohit
http://category-theory.mitpress.mit.edu/
======
dkarapetyan
This comes up every so often and people argue over the merits of learning
category theory or not or how useful or abstract it is. The answer is it is
very abstract and you shouldn't learn it expecting great dividends in your day
to day work. Like with most mathematics you should learn it because it will
change the way you think and solve problems. I definitely don't use calculus
in my day to day work but the idea of infinitesimal quantities, continuity,
and linear approximations have more than once helped me come up with an
approximation to a problem that has made the solution tractable.

If you are expecting to apply something immediately to your work then
combinatorics and probability theory are way more relevant and practical for
day to day programming work.

~~~
gclaramunt
But category theory has direct application to programming: (ignoring non-
termination), types and functions form a category and most of the concepts are
directly applicable. Functors/map are of everyday use and other CT results are
commonly used. Even JavaScript is getting functional, so CT is getting more
relevant and practical everyday

~~~
johncolanduoni
I love category theory, but I feel that its penetration of JavaScript or most
other languages doesn't (and likely won't) get much farther than monads and
functors. Many people who use functional languages don't even know about
applicatives, even though monads can be viewed as a specialization them.

If you're thinking about new programming paradigms I think the theory behind
CT versions is worth knowing, but if most of your monads are maybes or lists
it'll be of little practical value.

~~~
conistonwater
> _but if most of your monads are maybes or lists it 'll be of little
> practical value._

I think even this is maybe too much: if all you use are monads and functors,
then it's easy enough to learn monads and functors on their own, without any
"real" category theory.

------
yomritoyj
Category theory has served mathematicians well, but only because they had a
great mass of concrete detail which needed to be abstracted away.

An abstract framework like category theory can actually be harmful where there
isn't that much concrete detail to begin with. A personal example I faced was
being overwhelmed by category theory jargon when starting to learn Haskell a
couple of years back. My confidence returned only when I realized that there
was just one category in play with types as the objects and functions as the
arrows. The jargon was unnecessary. Today Haskellers discuss so many
interesting issues about the language and its implementation which do not fit
into the category theoretic framework at all.

~~~
fmap
In mathematics, I would describe category theory as an offshoot of
structuralism. The main idea is that instead of starting with some "premodel"
of what you want to study ("I want to study geometry on surfaces, so I'm
looking at subsets of R^3!") and then taking away structure ("...but what is
the preferred center of the universe? I better only look at properties which
are invariant under translations..."), you try to identify structure in your
problem and then determine the consequences. This is obvious in retrospect. If
your models describe reality and everything is built out of sets then is 0 an
element of 2?

Category theory provides useful tools for identifying structure. It's not
necessarily a good vocabulary to talk about these things. Forcing everything
into a first-order mold is typically confusing. On the other hand, there has
been a lot of work using category theory to solve real problems. This has
resulted in some sophisticated tools and a very "scalable" way of looking at
things (e.g. universal properties and adjunctions are everywhere).

Category theory is needlessly complicated. There are many redundant side
conditions, and the definitions are ... let's be charitable and call them
idiosyncratic. This is just more apparent when you apply catgeory theory to
programming languages. In semantics you already have a precise way of writing
statements (type theory) and you know that everything you can write down is
parametric. This eliminates almost all side conditions on most definitions in
category theory. So yes, coming from Haskell, catgeory theory probably looks
extremely complicated and not worth the effort to learn it.

However, some of the tools from category theory are as useful to computer
science as differentiation is to engineering. There are plenty of questions to
which you can calculate the answer using some elementary category theory. What
is the dual concept to the reader monad transformer? What is the eta law for
sum types? Can this data structure be a monad? If not, can I embed it into a
monad (e.g. using codensity)? These are all simple questions, but if you don't
know the general strategy for dealing with them it seems like I'm asking you
to solve a puzzle instead of asking you to compute 7 * 4.

~~~
tome
> you know that everything you can write down is parametric. This eliminates
> almost all side conditions on most definitions in category theory

That's interesting. Can you give an example of a side condition that
parametricity would allow you to avoid?

~~~
fmap
Any function f of type

    
    
      f : forall a b. (a -> b) -> F a -> F b
    

Such that f id = id is automatically a functor (respects composition).

In type theory, every equivalence is automatically natural.

There's a lot more and it's made worse by the fact that most of the side
conditions are redundant even in normal category theory. For instance, you can
specify an adjunction using two functions F : A -> B and G : B -> A, together
with an equivalence phi : forall a b. Hom(F a, b) = Hom(a, G b) such that phi
satisfies one additional equation. It follows from this that F, G are functors
and that the equivalence is natural. Since a lot of definitions in category
theory mention adjunctions you can usually simplify the definitions like this.
For example the definition of a Cartesian closed category in most textbooks
expands to something like 20 equations, but you can simplify it down to the
usual few equations which specify a model of simply typed lambda calculus.

~~~
tome
> the definition of a Cartesian closed category in most textbooks expands to
> something like 20 equations, but you can simplify it down to the usual few
> equations which specify a model of simply typed lambda calculus

Has that been written down somewhere convenient? I'd like to have a look.

By the way, I found lots of your comments on your post history also very
interesting!

------
Phithagoras
Table of contents at [http://category-
theory.mitpress.mit.edu/toc.html](http://category-
theory.mitpress.mit.edu/toc.html)

------
harveywi
Does anyone here have any experience using the Ologs proposed in the book for
doing knowledge modeling or other things? Some anecdotes, or in lieu of that,
opinions of this formulation compared to other knowledge model representations
would be interesting.

~~~
wisnesky
The FQL project uses ologs for data integration. There are many papers and
presentations at
[http://categoricaldata.net/fql.html](http://categoricaldata.net/fql.html) .

------
cousin_it
So. Just to clear up which math is good for a programmer to learn.

All computer science is divided into Theory A (algorithms and complexity) and
Theory B (logic and programming language design). Applications of category
theory are part of Theory B. If you're a programmer who wants to have real
world impact, you should study tons of Theory A and completely ignore Theory
B.

That sounds inflammatory, but it is unfortunately 100% true. All of Theory B
combined has less impact than a single hacker using Theory A to write Git or
BitTorrent.

~~~
zepolud
Sadly, Turing wasn't aware of this at the time -- think of the _real world
impact_ he could have had.

~~~
cousin_it
Turing's work was in algorithms, models of computation, and cryptanalysis. All
that is considered part of Theory A, see e.g.
[http://blog.computationalcomplexity.org/2003/03/theory-
and-t...](http://blog.computationalcomplexity.org/2003/03/theory-and-
theory-b.html).

~~~
zepolud
Take a minute and reflect on the fact that you're arguing Turing had nothing
to do with mathematical logic.

His doctoral advisor was Church, his work based on Gödel, his thesis named
_Systems of Logic Based on Ordinals_.

Comments like these show the perils of treating mathematics like a cookbook.
It's a very limiting mindset.

~~~
cousin_it
I'm arguing that Turing's impact on computing (most importantly, defining the
Turing machine) didn't have much to do with logic. His work on logic is also
important, but I don't think it's useful for a programmer.

------
bnj
Just on a formatting note, it would be great to have a static generator that
takes markdown input and generates this kind of html book with footnotes and
references. Similar to [spec-md]([http://leebyron.com/spec-
md/](http://leebyron.com/spec-md/)). Anyone know of interesting projects along
those lines?

~~~
dredmorbius
Incidentally, the document here smells very stongly of latex2html or a similar
generator.

~~~
gnufx
It's not that grotty. It looks more like TeX2page, from the navigation style
in particular (like the online SICP and How to Design Programs).

~~~
dredmorbius
I didn't mean to imply grotty at all, and apologise if I'd left that
impression. I was just noting that this had the hallmarks of LaTeX to HTML
translation.

Also the index.

------
CarolineW
Particularly of note:

    
    
        1.3   What is requested from the student
    
        The only way to learn mathematics is by doing
        exercises. One does not get fit by merely
        looking at a treadmill or become a chef by
        merely reading cookbooks, and one does not
        learn math by watching someone else do it.
        There are about 300 exercises in this book.
        Some of them have solutions in the text,
        others have solutions that can only be
        accessed by professors teaching the class.
    
        A good student can also make up his own
        exercises or simply play around with the
        material. This book often uses databases as
        an entry to category theory. If one wishes
        to explore categorical database software,
        FQL (functorial query language) is a great
        place to start. It may also be useful in
        solving some of the exercises.[0]
    

This is not a novel, and you don't learn by just reading things. You need to
engage topics like this in hand-to-hand combat, and if you're not willing to
do that - give up now. Your knowledge will be superficial, and ultimately
useless.

 _Added in edit: To reply to both (currently) comments, you don 't learn how
to program by just reading and not doing. You can learn_ about _programming,
but you won 't actually be able to program, and your knowledge will be
superficial. If that's your objective, just to know_ about _this topic, and
others in math, then fine. If you want to be able to_ use _your knowledge in
any meaningful way, my comment stands. It 's not enough just to read. You have
to engage, and do the work._

[0] [http://category-
theory.mitpress.mit.edu/chapter001.html#lev_...](http://category-
theory.mitpress.mit.edu/chapter001.html#lev_1-3)

~~~
mcguire
" _Some of them have solutions in the text, others have solutions that can
only be accessed by professors teaching the class._ "

And this is why I don't usually end up doing the exercises.

~~~
CarolineW
That's your choice, but in my experience that simply means that you don't end
up able to apply the knowledge you think you have acquired by reading about a
topic.

That might be fine for you, but it's an inherent limitation in reading about
something, rather than actually engaging in it.

I've edited my original comment to make a comparison, and expand on why I say
this.

But to take you up on this - some exercises have answers in the text. You
could do just those. Other exercises don't have the answers, just like code
that you write doesn't already exist. When you write the code you then have
the ability to check that it does what it's supposed to do.

The idea of having exercises without answers it to foster the ability to
understand when your answers are right. Most of the time it's easy to know if
you got the right answers, but it's finding the answer that's the challenge.
If you choose not to learn this topic, fine, that's your choice. My comment
just says: don't expect to understand the material at anything other than a
superficial level if all you do is read _about_ it.

As it says in the quoted section: One does not get fit by merely looking at a
treadmill.

------
paulpauper
Category theory , among with algebraic geometry, is one of the most
complicated concepts ever developed. Trying to extend it to a wide range of
applications seems like overkill. Yes, technically you can use it, but it's
like using an archaeology kit to dig a hole when a simple spade will do.

~~~
mej10
> most complicated concepts ever developed

I disagree. Much of Category Theory isn't complicated -- it is just really
abstract. So you need to have some concrete knowledge that you are going to
apply it to before you start learning it or alternatively "mathematical
maturity" (or as I like to call it "the ability to just accept abstract
statements and go with it").

As a tool it clarifies and unifies relationships between mathematical concepts
and domains like nothing else has.

~~~
paulpauper
but isn't abstract the same as complicated

~~~
paulpauper
I know I'm probably going to keep getting down-voted ,but if it's merely
abstract and not complicated ,why is category theory considered a difficult
course? They don't teach it in undergrad. Is it because it is poorly taught,
or students don't like abstractions, or students are ill-prepared, etc. The
question I'm digging at is what makes something hard to understand versus easy

~~~
yodsanklai
Maybe because category theory makes sense only after you have sufficient math
background? Just like it's easier to make sense of the definition of algebraic
structures when you're already familiar with enough of their instances.

An other reason, maybe category theory isn't that useful? I'm just speculating
here as I have only basic knowledge of category theory, maybe someone else can
enlighten us! While all the maths taught at undergraduate level are extremely
useful and pervasive in all areas of science, I'm still unsure about category
theory. It's certainly nice and elegant as it allows us to reframe different
theories and definitions in a same context, but is it useful for an engineer
or an applied mathematician?

~~~
Smaug123
Category theory is very useful for certain branches of pure mathematics (and
it instils a very useful mindset in the mathematician), but much less so for
applied mathematics.

Also you're quite right that category theory only really starts to make sense
when you have a big stock of examples, like "group theory" and "poset theory"
and "topology" and "set theory". Once you've got those examples, you can
detect these common threads between them and call them "category theory".

~~~
Koshkin
On the other hand, at least some of the ideas from the category theory have
already made their way into the _practice_ of programming. I am talking about
the notion of a monad. It has already become an important tool in functional
programming; but even in mostly-imperative programming languages such as C#
one can discern important patterns as instances of this concept. Contrary to
the common perception, it is not hard to understand. Two basic examples: the
optional (a.k.a. nullable) type construct is an example of a monad (called
'Maybe' monad in Haskell); a generic list construct is another one. I think it
is enlightening to be able to see a common pattern behind these, seemingly
different, things. And this is exactly where the power and the usefulness of
the category theory lies - in mathematics or elsewhere.

~~~
dllthomas
> the optional (a.k.a. nullable) type construct is an example of a monad

Nullable (in the C# sense) does not form a monad, because it does not form a
functor, because you cannot write fmap, because it does not nest.

