Easy Category Theory Part I: The Basics
Published: 2019-04-30 01:05:51

---
title: 'Easy Category Theory Part I: The Basics'
description: Category Theory concepts explained using simple metaphors and illustrations.
published: true
cover_image: https://cdn-images-1.medium.com/max/800/0*X1BAXzgzlwa5kFgW
series: Easy Category Theory
---

Category Theory may be important to learn as functional programming is coming back into the mainstream. If you a have a passion for discovering abstractions, CT promises to be the ultimate abstraction. As I learn category theory, I will add an article to this series in which I will explain the concept I have learned in an attempt to further my own understanding and hopefully help you learn this vast subject as well.

There are plenty of articles, books, papers etc for learning CT. My goal with these articles is not to provide the best explanation or an exhaustive explanation that uses all the mathematical notation.  I only hope to provide _another_ explanation that _may_ trigger an epiphany for the more guided learning I hope you are doing. My explanations here are tuned to the way I learn best, metaphors, pictures, and simple language.

The strategy I recommend for learning CT is to use an introductory book as a guide to the concepts to learn and the order in which to learn them.  Then consult other resources (YouTube, articles like this one, etc) to chip away at each concept until your understanding is satisfactory and internalized enough to move to the next concept.

> Disclaimer: I am not a mathematician and I do not have a degree. I am only just beginning to learn Category Theory and anything I say should be independently verified as correct.

### What is Category Theory?

A _theory_ in mathematics is the attempt to seek out patterns and suggest possibilities about these patterns. Then assemble these possibilities into a well-defined set of ideas using mathematical concepts, language, and notation to form statements (axioms) that are taken to be true and built upon to form further axioms.

_Category theory_ is a somewhat special mathematical theory in that the axioms attempt to formalize the structure of all mathematics. The patterns this theory seeks to explain apparently underly every branch of mathematics and more. That is to say, if you were to replace concepts in any branch of mathematics with the most abstract notions of those objects and their rules, you would then be dealing with CT.

### What is a Category?

A category has two parts and two rules. The two parts are _things_ and _indicators_. An _indicator_ is some process which can be supplied with a _thing_ and indicate (point out, surface, return, show) the same or another _thing_.  The two rules for a category are that _indicators_ must be composable with associativity and there must be an identity _indicator_ for every _thing_. 

**Composable** means if an indicator uses _type A things_ to indicate _type B things_ and another indicator uses _type B things_ to indicate _type C things_, then there is an indicator that can use _type A things_ to indicate _type C things_, and that indicator is the composition of the two indicators i.e. If we can go from A->B->C, we can go directly from A->C.

**Associativity** is defined by saying a group of quantities connected by operators gives the same result whatever their grouping, as long as their order remains the same.  In CT this means, you can start following arrows at any point as long as you don't change where they point.

**Identity** means if I have _things_ and give one to my _indicator_ it will indicate to me that exact _thing_ I gave it.

I use this non-specific language intentionally. It gets difficult to separate the abstract nature of a category from specific examples of a category. For example _indicators_ are often thought of as functions, as in a mathematical function like f(x), something that takes an input and produces an output. However, _indicators_ don’t have to be transformations. Again, the only rules for what qualifies as an indicator are composable with associativity and an identity indicator exists.  Relations are also _indicators_.  If I have a 5 and I use the relation ≤, what I have is an _indicator_ which takes _things_ of type "set of all numbers" and indicates all other _things_ of type "set of numbers less than or equal to 5".

#### Simplifying the Language

*   **Objects:** _things_ such as real numbers, words, other categories or even _arrows_.  Pretty much anything an be an object.
*   **Arrows:** _indicators_ which are processes that use objects to indicate other objects.  They must be composable with associativity.

So using our new language, **categories are arrows that use objects of a certain kind to point at other objects of the same kind. These arrows must be associative and composable**.  The category contains ALL such indicators and objects.

![](https://cdn-images-1.medium.com/max/1200/1*edUjihWVkI60kz1asOwIsw.png)

### Concept Example

In programming, classes (or more accurately types) are an example of a category. Let’s fill in the blanks:

#### Category of Types

*   **Objects:** Types
*   **Arrows:** Hierarchy (inheritance)
*   **Composable**: Yes. If type C inherits from type B, and type B inherits from type A, then type C inherits from type A. Notice the order in which these types are defined (grouped, evaluated) does not matter from a hierarchy sense i.e. (C <- (B <- A)). However the order in which they are composed does, i.e. C <- B <- A is not the same as B <- C <- A
*   **Identity:** Yes. Type A could inherit from type A in which case you would have type A, though since this is trivial no language that I know of supports it.

#### Category of Metaphors

*   **Objects:** anything
*   **Arrows:** mental mapping
*   **Composable:** Yes. If I imagine a piece of wood represents a boat, and a boat represents travel, I can imagine a piece of wood represents travel.
*   **Identity:** Yes. I can always imagine a piece of wood represents a piece of wood.

### What’s Next?

The next article will discuss what it means for two categories to be close enough to the same to be considered equal for most intents and purposes.

### Resources
I recommend this book: 
https://www.amazon.com/gp/product/052171916X/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

And Bartoz Milewski's (free!) youtube channel: 
https://www.youtube.com/playlist?list=PLbgaMIhjbmEnaH_LTkxLI7FMa2HsnawM_