A 10 minute lightning talk that highlights the 3 most important aspects of Category Theory as it relates to Functional Programming.
Size: 1.22 MB
Language: en
Added: Jun 27, 2017
Slides: 22 pages
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.
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 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