Crash course in Category Theory

Key Point:

Haskell & any FP compiler don’t check the Category Theory proof if your codes (eg. fmap) follow Functor’s Laws (eg. Preserve structure, identity) or Monad’s Laws !


Programmers need Advanced Math ?

As software becomes more complicated for high-speed trains, driverless cars, missile weapons. .. and AI deeplearning algorithm, we can’t depend our life safety on the programmers who don’t understand the advanced maths behind these algorithms.

The Advanced Math is the Category Theory – the most advanced math foundation above “Set Theory” since WW2. Functional Programming is based on Category Theory with mathematical functions – always output correctly with no “side-effects”.

Category Theory – Purest of pure mathematical disciplines may also be a cornerstone of applied solutions in computational science

There exists in almost all Universities a clear division between pure and applied mathematics. A friendly (and sometimes not so friendly) rivalry exists between both sides of the divide, with separate conferences, separate journals and in many cases even a whole separate language. Category Theory was seen as such an abstract area of research that even pure mathematicians started to refer to it as “abstract nonsense“, and until the mid 1980’s almost all category theorists occupied a place hidden somewhere up above the ‘cloud level’ in the highest reaches of the peaks that defined “pure” maths.

By the mid 1990’s and then by the turn of the millenium, a whole world of computer programmers were learning basic category theory as part of their induction into functional programming. The best known product of these efforts is the Haskell language, but even in the past 7 or 8 yrs, workshops on category theory for computer programmers of all types have flourished and proliferated. It is almost as if there are two separate communities masquerading as one – mathematical category theory and computer programming category theory – and never the twain would meet. Or so it seemed, until now.

Alejandro Serrano: Category Theory Through Functional Programming

(Part 1/3) – λC 2017

What is Category ?


Morphism (Arrows )

Rule1: Associative

Rule 2: Identity

A <– C –> B

Product of Categories : A x B


Sum of Categories: A + B


(Either a b)


Reverse all arrows.


Functor F: C-> D

Mapping of all objects (A, B) in categories C,D

Mapping of arrows f
f : A -> B
Ff : FA -> FB (preservation)
F Id = Id
F (f。g) = Ff。Fg


Constant C -> F
FC = k
Ff = Id

Arrow Functor F: C -> D

For any object A in C,

F A = D -> A
(Functional Type is also Type)

Functors compose !

Category of categories:

Objects: categories

Arrows : Functors

Haskell Category (Hask) is always Endo-Functor, ie Category Hask to itself.

Mapping of arrows.

Mapping of Objects = predefined

(Part 2/3) – λC 2017

(part 3/3) – λC 2017