on software

Some thoughts on categories

Dec 11, 2017 • 3 min read

There is simple idea once told by Feynman — the purpose of physics is to seek the simplest theory that would describe as much of the natural phenomena as possible. That the idea behind electrodynamics of Maxwell or QED. Each new grand theory was able to descibe more of the world and in the same time be simple.

That is a beautiful idea with very clear purpose which gives great results. So why we (software engineers) don't take it on and embrace it? Why some the best ideas around enginnering aren't yet formalized and unified, e.g. best practices such as KISS or DRY? Are they inherently not formalazable? It can't be true if we assume computer sciense is based on math, there should be some way to derive them from the math of computer science and maybe once we learn how to derive them we might learn how to derive new best practices that aren't yet established from emphirical knowledge. We've seen this happen in physics many times, most recently with airlplanes. We've built them from empirical knowledge and only after that the actual laws of aerodynamic were built which led to better planes with jet propolsuin.

This article is some of my thoughts around the subject.


The mathamatical basis of software engineering lays in the category theory and I don't mean the complex parts of it, but the most basic and simple subjects. Let's explore this a bit.

So category theory is a theory about categories, and categies are nothing more than bunch of objects connected with arrows.

In software engineering we're interested in specific kind of category that is called catefory of types. In csategory of types objects are actual types and arrows are functions between them.

Category of types

From this simple definition we can make an observation that objects aren't relevant, they are just there to mark the start and end points for the arrows. And if translated, types don't matter in category, arrows do. Types are here for functions to have input and output. It's also not really important how many arrows we have between objects. If we have 1, 2 ot Infinity everything stays the same.

If we combine this observation the only great idea of categories we will have basis of software engineering in all its forms.

The only great idea of categories is the composition.


In category theory, composition is the ability to derive direct arrows betweein two objects.


if we have the arrows length and isOdd between String, Number and Boolean, we can compose these arrows to get a direct arrow length ◦ isOdd. That's the composition. Note however two rules:

length ◦ isOdd != isOdd ◦ length
toLower ◦ length = length ◦ toLower = length

OK, at this moment we some basics of the software engineering and you probably already can see some of the characteristics of functional programming languages. But this takes effect not only on functional langauges but to imperative and other paradigms too. It's just thta functional langauges are closer to the math.

Don't Repeat Yourself

Or simply DRY. So can we derive it from category of types as it's given in previos chapters. It appears to be true. Let's say we have category with 4 objects:

About the author

I’m Ike, a software engineer from Armenia. This blog is me sharing my thoughts on engineering. More about me.
Dec 11, 2017 • 3 min read
Some thoughts on categories
Dec 11, 2017 • 3 min read
Some thoughts on categories