What is Category Theory?
Category theory is all about composition. Defining a category is simple, it simply has objects, morphisms and a set of axioms.
A morphism is an arrow between two objects, and morphisms are composable. That simply means that if you have three objects , and :
And two morphisms and :
Then those two morphisms can be composed:
The first axiom states that composition of morphisms is associative:
The second axiom states that every object in a category has an identity morphism:
And this identity morphism is the unit of composition:
Given two objects and in a category , there may be zero or more morphisms between them. This set of morphisms is called the hom-set:
Translating the above into programming terms you can think of objects as types and morphisms as functions. In Haskell we only operate on the single category called , which is the set of Haskell types and functions. This is only a very simplified view though, with many details omitted, such as partial/total functions and the bottom but all those details will come in due course.
Furthermore, and more importantly, software can be thought of as a problem involving composition. We break a big program down into smaller and smaller parts, solving each of those parts and then finally compose them back into the whole. By decomposing problems down into smaller pieces our limited brains are better able to reason about them. And that is exactly what category theory is all about!
An important thing to remember about category theory is that we are trying to remove details of the thing we are looking at. Eventually we only want to be thinking about morphisms and how they relate to the entire universe of the category. That's the fundamental step in breaking away from more traditional thinking (ie. in terms of sets of elements and functions on those elements).