Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As someone interested in functional programming, but works almost entirely in imperative languages, is category theory worth learning?

Function programming heavily impacted how I write imperative code. Would I have similar revelations with category theory – maybe write better abstractions?



> Would I have similar revelations with category theory – maybe write better abstractions?

Maybe, but it's not a given. (Haskell folks might have a different view due to their language being a closer match to the theory)

My sense is Category Theory is one of those things that is useful for explaining things in retrospect, rather than used as a constructive tool. It exposes inconsistencies in your current model, and helps clear up your thinking. John D. Cook wrote a piece on Applied Category Theory which makes the point that theory itself is perhaps less useful than the discipline of thinking categorically [1].

I think Category Theory can guide the design of certain types of tools that deal with relationships. LINQ (in C#) for instance was guided by category theory. If you wanted to come up with a new kind of SQL, category theory could be helpful in designing abstractions that are orthogonal and clean.

But the design of these types of tools remain a small, specialized domain within programming. It's somewhat analogous in my mind to metaclasses in Python: classes are sufficient for the most part, only framework developers will likely ever need metaclasses (to generate classes).

In most day-to-day programming, it seems unlikely that category theory will have as much an impact on practice as does, say, simple principles derived from functional programming. In fact, there may even be negative consequences from over-abstracting your code.

[1] https://www.johndcook.com/blog/applied-category-theory/


Some light category theory is pretty useful (functors, monads, lenses, etc). However, I think it often goes way overboard into premature abstraction territory with many functional programmers. The type tetris required to make some of this stuff compile, and the mental overhead, can easily exceed the abstraction gained.

The category theory should also be viewed as more a close analogy to the programming problem, rather than an exact correspondence. These abstractions sometimes leak, especially in numerical code.

edit: More complex and specialized abstractions are useful on fewer problems than simple, general abstractions. In addition, they have more mental overhead. So you work harder for a less useful abstraction, and you make it harder for others to use and understand your work.


> is category theory worth learning?

Yes. Very much so. Especially if you're programming functionally. It will explain why all this is the way it is. Why sum types and product types are what they are, the big picture on functors, monads, etc, etc.

I like Bartosz Milewski's introduction [1][2] where he states (paraphrasing) that he started programming back in the day with assembly, and as programs got more difficult we needed higher level abstractions, so he moved to procedural languages, and then after that another higher abstraction was OO, but he realised that OO has a fundamental problem: objects don't compose, and so he found himself functional programming with Haskell... each time looking for better abstractions.

Category Theory is the ultimate abstraction and although you can't write code with it, you can step outside of the detail of complex solutions and think about the bigger picture and then use that bigger picture to help you build your detail. And that's why I think it's valuable.

I particularly like his journey too, as it exactly reflects my own.

[1] Category Theory for Programmers - https://github.com/hmemcpy/milewski-ctfp-pdf

[2] https://www.youtube.com/user/DrBartosz/playlists


It generally is not going to help you write application code, no.

Heavy FP folks sometimes study it out of natural curiosity though.

There are a few examples of libraries that are directly influenced by category theory, but they are few in number.


http://math.ucr.edu/home/baez/rosetta.pdf

It's worth reading this if you've got a math background at all. It's a nice summary of what Category Theory is and potential applications for it.


You ask as if it is somehow a huge investment. Category theory is not that hard. It became the language of (almost all) contemporary mathematics. Many mathematicians learn it during the first years of their studies. Its core is very small, and most (if not all) of its usefulness comes from the language itself. In other words, there are almost no theorems in (pure) category theory, but there are many definitions and a great deal of examples. If you know at least some abstract algebra, learning category theory will be quite easy. And this language opens the door to conceptual understanding of many areas of mathematics, logic, functional programming, and some other applied sciences.


It can be useful, precisely as much as any formal framework can help guide your thinking. Categories suggest a particular type of abstraction. It's highly abstract. It can be quite useful. However, if you find another algebraic formalism, that can be useful also.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: