© 2015 Pivotal Software, Inc. All rights reserved.© 2015 Pivotal Software, Inc. All rights reserved. 1
Category Theory for Mortal Programmers
Stephan February
@beardpappa
http://hashbangbin.sh
© 2015 Pivotal Software, Inc. All rights reserved. 3
What is Category Theory
• Abstraction • Objects • Arrows (morphisms)
© 2016 Pivotal Software, Inc. All rights reserved. 4
Relation to Programming
f : A => B
g : B => C
g o f ~ g( f(A)) : A => C
domain(f)
codomain(f)
© 2016 Pivotal Software, Inc. All rights reserved. 5
Relation to ProgrammingWhat makes something a Category ?
composition :
f: A => B and g : B => Cgiven
g o f : A => C∃
objects :
morphisms : f, g
A, B, C
identity : id1: A => A or id2 : B => B
id1
id2
© 2016 Pivotal Software, Inc. All rights reserved. 6
Category Laws
id1
id2
Associative Law
Identity Law
(h o g) o f = h o (g o f)
f o id1 = id1 o f = f
© 2015 Pivotal Software, Inc. All rights reserved. 7
FunctorsCategories : Functional Design Patterns
Apply a function f: x: Int => x2 to the sequence [1,2,3,4,5]
[1,2,3,4,5].map{ x => x * x }
© 2015 Pivotal Software, Inc. All rights reserved. 9
Functor Recap
(A => B) (T[A] => T[B])
General Shape
Our Category
© 2015 Pivotal Software, Inc. All rights reserved. 10
Monads (homework) Categories : Functional Design Patterns
(A => T[B]) (T[A] => T[B])flatMap
General Shape
ReferencesProgramming Scala 2nd Edition
StackOverFlow: A Monad Is Just a Monoid in the Category of Endofunctors. Whats The Problem ?
YouTube: Category Theory Lulz - Ken Scambler
YouTube: Category Theory, The Beginner's Introduction
Blog: Functors, Monads, Applicatives can be so simple
An Introduction to Category Theory