Category Theory in 10 Minutes

JordanParmer 4,136 views 22 slides Jun 27, 2017
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

A 10 minute lightning talk that highlights the 3 most important aspects of Category Theory as it relates to Functional Programming.


Slide Content

Category Theory in 10 Minutes Jordan Parmer @ProfParmer

What’s Category Theory?

What’s Category Theory? Mathematical study of abstract algebras of functions Systems of functions among some objects

What’s a Category?

A B f

A B f Object Object Arrow/Morphism

A B f Object Arrow/Morphism Object Domain (f) Cod omain (f)

A B C f g

A B C f g g ∘ f g ∘ f = g ( f ( a ) ) Composite

A B C f g g ∘ f Object d omain(f) Arrow Composite Object codomain(f) domain(g) Arrow Object codomain(g) ( g ◦ f )( a ) = g ( f ( a ) ) a ∈ A

A B C f g g ∘ f Unit (identity) law: 1 A : A → A, f ∘ 1 A = f = 1 B ∘ f Associativity law: h ∘ (g ∘ f) = (h ∘ g) ∘ f

A B C h g g ∘ f D f h ∘ g

Category theory is just mathematicians playing Portal.

Oh the names we’ll use... Category theory is comprised of many small, simple laws. Adding a certain combination of laws together forms various algebraic structures each with their own name.

https://medium.com/@sinisalouc/demistifying-the-monad-in-scala-part-2-a-category-theory-approach-2f0a6d370eff

Functional Concepts Functor Transforms from one category to another. A => B B => C Endofunctor Transforms objects between same category. (e.g. Functor in the category of types) Int => Int String => Int String => TaskResult

Functional Concepts Functor Transforms from one category to another. A => B B => C Endofunctor Transforms objects between same category. (e.g. Functor in the category of types) Int => Int String => Int String => TaskResult Functors in most programming languages are all endofunctors because most programming languages are in the category of Types.

Functional Concepts Functor Transforms from one category to another. A => B B => C Endofunctor Transforms objects between same category. (e.g. Functor in the category of types) Int => Int String => Int String => TaskResult Often called ‘map’ or ‘fmap’ function Ex: “pickle”.map(c => c + “z”) Yields: (“pz”, “iz”, “cz”, “kz”, “lz”, “ez”)

Functional Concepts Semigroup Append Append 1 + 2 “Hello” + “World” [1, 2, 3] + [4, 5, 6] Monoid Identity Append Identity 0 + 1 == 1 + 0 == 1 “” + “A” == “A” + “” == “A” [ ] + [1] == [1] + [ ] == [1] *Append -> binary associative operator

Functional Concepts Monad Identity as Apply Append as Flatten Monoid in the category of endofunctors. For all practical purposes, it is a monoid that can be flattened if the inner type is itself a monoid. Maybe (Maybe(T)) to Maybe(T) List(List(T)) to List(T) List(Maybe(T)) to List(T)

Chaining Monads Pictures by Aditya Bhargava https://tinyurl.com/cmvrfpb “Bind” operation plucks value from monadic context and applies it to next function returning it back in context.

Thanks! ANY QUESTIONS? You can find me at @ ProfParmer