your data structures are made of maths!

196
Category Theory for Beginners Your data structures are made of maths ! Melbourne Scala User Group Mar 2015 @ KenScambler

Upload: kenbot

Post on 14-Jul-2015

1.044 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: Your data structures are made of maths!

Category Theory for Beginners

Your data structures

are made of maths!Melbourne Scala User Group Mar 2015

@KenScambler

Page 2: Your data structures are made of maths!

Data structures

More and more “logical”

Less low-level memory/hardware connection

More and more support for immutability

We can use maths to reason about them!

Category Theory can reveal even deeper symmetries

Page 3: Your data structures are made of maths!

Algebraic Data Types

Constants, sums, products, exponents

We can directly manipulate them with algebra!

Page 4: Your data structures are made of maths!

Products

A × B

Page 5: Your data structures are made of maths!

NinjaTurtles

Page 6: Your data structures are made of maths!

NinjaTurtles

×

BluesBrothers×

Page 7: Your data structures are made of maths!

NinjaTurtles BluesBrothers

=

NTs and

BBs× =

×

Page 8: Your data structures are made of maths!

=4 × 2 8

Page 9: Your data structures are made of maths!

Integers as types?

We can actually use integers to represent our types!

The integers correspond to the size of the type

Page 10: Your data structures are made of maths!

Products in code

(NinjaTurtle, BluesBrother)

Page 11: Your data structures are made of maths!

(NinjaTurtle, BluesBrother)4

Page 12: Your data structures are made of maths!

(NinjaTurtle, BluesBrother)4 2

Page 13: Your data structures are made of maths!

NinjaTurtle (,) BluesBrother4 2×

Page 14: Your data structures are made of maths!

(NinjaTurtle, BluesBrother)8

Page 15: Your data structures are made of maths!

case class TurtleAndBrother(foo1: NinjaTurtle, foo2: BluesBrother)

Page 16: Your data structures are made of maths!

case class TurtleAndBrother(foo1: NinjaTurtle, foo2: BluesBrother)

4

Page 17: Your data structures are made of maths!

case class TurtleAndBrother(foo1: NinjaTurtle, foo2: BluesBrother)

42

Page 18: Your data structures are made of maths!

case class TurtleAndBrother(…)NinjaTurtleBluesBrother

42×

Page 19: Your data structures are made of maths!

case class TurtleAndBrother(foo1: NinjaTurtle, foo2: BluesBrother)

8

Page 20: Your data structures are made of maths!

trait Confluster {def defrabulate(): BluesBrotherdef empontigle(): NinjaTurtle

}

Page 21: Your data structures are made of maths!

trait Confluster {def defrabulate(): BluesBrotherdef empontigle(): NinjaTurtle

}

2

Page 22: Your data structures are made of maths!

trait Confluster {def defrabulate(): BluesBrotherdef empontigle(): NinjaTurtle

}4

2

Page 23: Your data structures are made of maths!

trait Confluster { def; def; }BluesBrother

NinjaTurtle2

Page 24: Your data structures are made of maths!

trait Confluster {def defrabulate(): BluesBrotherdef empontigle(): NinjaTurtle

}

8

Page 25: Your data structures are made of maths!

Sums

A + B

Page 26: Your data structures are made of maths!

true

false

Boolean

Page 27: Your data structures are made of maths!

true

false

+

Boolean Shapes+

Page 28: Your data structures are made of maths!

true

false

+ =

Boolean Shapes

Boolean or

Shapes

true

false

+ =

Page 29: Your data structures are made of maths!

true

falsetrue

false

=2 + 4 6

Page 30: Your data structures are made of maths!

sealed trait Holidaycase object Christmas extends Holidaycase object Easter extends Holidaycase object AnzacDay extends Holiday

Sums in code

Page 31: Your data structures are made of maths!

sealed trait Holidaycase object Christmas extends Holidaycase object Easter extends Holidaycase object AnzacDay extends Holiday

1

Page 32: Your data structures are made of maths!

sealed trait Holidaycase object Christmas extends Holidaycase object Easter extends Holidaycase object AnzacDay extends Holiday

11

Page 33: Your data structures are made of maths!

sealed trait Holidaycase object Christmas extends Holidaycase object Easter extends Holidaycase object AnzacDay extends Holiday

111

Page 34: Your data structures are made of maths!

sealed trait Holiday, case, extendsChristmasEasterAnzacDay

111

+

Page 35: Your data structures are made of maths!

sealed trait Holidaycase object Christmas extends Holidaycase object Easter extends Holidaycase object AnzacDay extends Holiday

3

Page 36: Your data structures are made of maths!

sealed trait Opt[A]case class Some[A](a: A) extends Opt[A]case class None[A] extends Opt[A]

Page 37: Your data structures are made of maths!

sealed trait Opt[A]case class Some[A](a: A) extends Opt[A]case class None[A] extends Opt[A]

A

Page 38: Your data structures are made of maths!

sealed trait Opt[A]case class Some[A](a: A) extends Opt[A]case class None[A] extends Opt[A]

A1

Page 39: Your data structures are made of maths!

sealed trait Opt[A], case class, extendsSome[A](a: A)None[A]

A1

+

Page 40: Your data structures are made of maths!

sealed trait Opt[A]case class Some[A](a: A) extends Opt[A]case class None[A] extends Opt[A]A + 1

Page 41: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]

Page 42: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]3

Page 43: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]3 2

Page 44: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]3 2 + 1

Page 45: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]3 3

Page 46: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]3 3+

Page 47: Your data structures are made of maths!

Either[Holiday, Opt[Boolean]]6

Page 48: Your data structures are made of maths!

Exponents

BA

Page 49: Your data structures are made of maths!

Exponents

BA

A type to the power of another type?? Huh?

Page 50: Your data structures are made of maths!

true

false

Boolean

Page 51: Your data structures are made of maths!

true

false

Boolean

Shapes

Page 52: Your data structures are made of maths!

true

false

Boolean

Shapes = Shapes Boolean

true

false

true

false

true

false

true

false

true

false

true

false

true

false

true

false

Page 53: Your data structures are made of maths!

true

false

23 =

true

false

true

false

true

false

true

false

true

false

true

false

true

false

true

false

8

Page 54: Your data structures are made of maths!

Function types =

exponents!

A B = BA

Page 55: Your data structures are made of maths!

Exponents in code

def getTurtle(): NinjaTurtles

Page 56: Your data structures are made of maths!

def getTurtle: () => NinjaTurtles

Page 57: Your data structures are made of maths!

def getTurtle: () => NinjaTurtles1

Page 58: Your data structures are made of maths!

def getTurtle: () => NinjaTurtles1 4

Page 59: Your data structures are made of maths!

def getTurtle: () => NinjaTurtles1 4

Page 60: Your data structures are made of maths!

def getTurtle: () => NinjaTurtles41

Page 61: Your data structures are made of maths!

def getTurtle: () => NinjaTurtles4

Page 62: Your data structures are made of maths!

Functions “with no arguments”

are tacitly from a singleton type

such as Unit

Singleton types carry no

information.

Page 63: Your data structures are made of maths!

trait State[S, A] {def run(state: S): (A, S)

}

Page 64: Your data structures are made of maths!

trait State[S, A] {def run(state: S): (A, S)

}A×S

Page 65: Your data structures are made of maths!

trait State[S, A] {def run(state: S): (A, S)

}S A×S

Page 66: Your data structures are made of maths!

trait State[S, A] {def run(state: S): (A, S)

}(A×S)S

Page 67: Your data structures are made of maths!

{•}Zero

On

eProduct

sSum

sExponent

s

Sets Scala Algebra

{}

A×B

A∪B

AB

(A, B)

0

1

AB

A+B

A -> B

A \/ B

Nothing

Unit

BA

Page 68: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

Page 69: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

A×B

Page 70: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

A×B C

Page 71: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

CAB

Page 72: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

CAB

A(B C)

Page 73: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

CAB

ACB

Page 74: Your data structures are made of maths!

Currying

def tupled[A, B, C](a: A, b: B): C

def curried[A, B, C]: A => (B => C)

CAB

CAB

Page 75: Your data structures are made of maths!

Recursion

sealed trait List[+A]

case class Cons[A](h: A, t: List[A]) extends List[A]

case object Nil extends List[Nothing]

Page 76: Your data structures are made of maths!

sealed trait List[+A]

case class Cons[A](h: A, t: List[A]) extends List[A]

case object Nil extends List[Nothing]

A

Page 77: Your data structures are made of maths!

sealed trait List[+A]

case class Cons[A](h: A, t: List[A]) extends List[A]

case object Nil extends List[Nothing]

A L(A)

Page 78: Your data structures are made of maths!

sealed trait List[+A]

case class Cons[A](h: A, t: List[A]) extends List[A]

case object Nil extends List[Nothing]

A × L(A)

Page 79: Your data structures are made of maths!

sealed trait List[+A]

case class Cons[A](h: A, t: List[A]) extends List[A]

case object Nil extends List[Nothing]

A × L(A)

1

Page 80: Your data structures are made of maths!

sealed trait List[+A]

case class Cons[A](h: A, t: List[A]) extends List[A]

case object Nil extends List[Nothing]

1 + A × L(A)

Page 81: Your data structures are made of maths!

Expanding a list…

L(a) = 1 + a × L(a)

Page 82: Your data structures are made of maths!

Expanding a list…

L(a) = 1 + a L(a)

Page 83: Your data structures are made of maths!

Expanding a list…

L(a) = 1 + a L(a)

= 1 + a (1 + a L(a))

Page 84: Your data structures are made of maths!

Expanding a list…

L(a) = 1 + a L(a)

= 1 + a (1 + a L(a))

= 1 + a + a2 (1 + a L(a))

Page 85: Your data structures are made of maths!

Expanding a list…

L(a) = 1 + a L(a)

= 1 + a (1 + a L(a))

= 1 + a + a2 (1 + a L(a))

= 1 + a + a2 + a3 + a4 + a5…

Page 86: Your data structures are made of maths!

Expanding a list…

L(a) = 1 + a L(a)

= 1 + a (1 + a L(a))

= 1 + a + a2 (1 + a L(a))

= 1 + a + a2 + a3 + a4 + a5…

Nilor 1-length

or 2-length

or 3-lengthor 4-length

etc

Page 87: Your data structures are made of maths!

What does it mean for

two types to have the

same number?

Page 88: Your data structures are made of maths!

Not identical… but

isomorphic

Page 89: Your data structures are made of maths!

Terminology

isomorphism

Page 90: Your data structures are made of maths!

Terminology

isomorphism

Equal

Page 91: Your data structures are made of maths!

Terminology

isomorphism

Equal-shape-ism

Page 92: Your data structures are made of maths!

Terminology

isomorphism

“Sorta kinda the same-ish”

but I want to sound really

smart- Programmers

Page 93: Your data structures are made of maths!

Terminology

isomorphism

“Sorta kinda the same-ish”

but I want to sound really

smart- Programmers

Page 94: Your data structures are made of maths!

Terminology

isomorphism

One-to-one mapping

between two objects so

you can go back-and-forth

without losing information

Page 95: Your data structures are made of maths!

These 4

Shapes

Wiggles

Setfunctions

Set

4 = 4

Page 96: Your data structures are made of maths!

These 4

Shapes

Wiggles

Page 97: Your data structures are made of maths!

These 4

Shapes

Wiggles

Page 98: Your data structures are made of maths!

There can be lots of

isos between two

objects!

If there’s at least one, we

can say they are

isomorphic

or A ≅ B

Page 99: Your data structures are made of maths!

Programming

language

syntaxProgramming

language

FEATURES!!!

NAMESNAMESNAMES

actualstructure

Programming

language

syntax

Programming

language

FEATURES!!!

NAMESNAMESNAMES

actualstructure

class Furpular { class Diggleton {

} }

Page 100: Your data structures are made of maths!

Programming

language

syntaxProgramming

language

FEATURES!!!

NAMESNAMESNAMES

actualstructure

Programming

language

syntax

Programming

language

FEATURES!!!

NAMESNAMESNAMES

actualstructure

class Furpular { class Diggleton {

} }

Page 101: Your data structures are made of maths!

Programming

language

syntaxProgramming

language

FEATURES!!!

NAMESNAMESNAMES

actualstructure

Programming

language

syntax

Programming

language

FEATURES!!!

NAMESNAMESNAMES

actualstructure

class Furpular { class Diggleton {

} }

Looking at data structures

algebraically lets us

compare the true structure

Page 102: Your data structures are made of maths!

actualstructurebut faster

actualstructure

Knowing an isomorphism, we

can rewrite for

• Performance

• Memory usage

• Elegance

with proven correctness!

Page 103: Your data structures are made of maths!

actualstructurebut faster

actualstructure

Knowing an isomorphism, we

can rewrite for

• Performance

• Memory usage

• Elegance

with proven correctness!*

*mumble mumble non-termination

Page 104: Your data structures are made of maths!

Category Theory

object

A B

objectarrow

Arrows join objects. They can

represent absolutely

anything.

Page 105: Your data structures are made of maths!

Categories generalise

functions over sets

A Bf

Page 106: Your data structures are made of maths!

Arrows compose like

functions

A B Cf g

Page 107: Your data structures are made of maths!

Arrows compose like

functions

A Cg ∘ f

Page 108: Your data structures are made of maths!

A

Every object has an identity arrow,

just like the identity function

Page 109: Your data structures are made of maths!

That’s all a category

is!

Page 110: Your data structures are made of maths!

Products in CT

A × BA Bfirst seco

nd

trait Product[A,B] {def first: A def second: B

}

Page 111: Your data structures are made of maths!

Sums in CT

A + BA BLeft Right

sealed trait Sum[A,B]

case class Left[A,B](a: A) extends Sum[A,B]

case class Right[A,B](b: B) extends Sum[A,B]

Page 112: Your data structures are made of maths!

Opposite categories

C Cop

A

B

C

g ∘ f

f

g

A

B

C

f ∘ g

f

g

Isomorphic!

Page 113: Your data structures are made of maths!

A

B

C

g ∘ f

f

g

A

B

C

f ∘ g

f

g

Just flip the arrows, and

reverse composition!

Page 114: Your data structures are made of maths!

A

A×B

B

A product in C is a sum in Cop

A sum in C is a product in Cop

A+B

B

A

C Cop

Page 115: Your data structures are made of maths!

Sums are

isomorphic to

Products!

Page 116: Your data structures are made of maths!

Terminology

dual

An object and its equivalent in the

opposite category are

to each other.

Page 117: Your data structures are made of maths!

Terminology

Co-(thing)

Often we call something’s dual a

Page 118: Your data structures are made of maths!

Terminology

Coproducts

Sums are also called

Page 119: Your data structures are made of maths!

Tightening the definitions

A × BA Bfirst seco

nd×

×

trait ProductPlusPlus[A,B] {def first: Adef second: Bdef banana: Bananadef brother: BluesBrother

}

Page 120: Your data structures are made of maths!

A × BA Bfirst seco

nd×

×

Does that still count as A × B?

Page 121: Your data structures are made of maths!

A × BA Bfirst seco

nd×

×

No

way!

Page 122: Your data structures are made of maths!

A × BA Bfirst seco

nd×

×

Umpire

theA someB

trait Umpire {def theA: Adef someB: B

}

Page 123: Your data structures are made of maths!

A × BA Bfirst seco

nd×

×

Umpire

theA someB

trait Umpire {def theA: Adef someB: B

}

unique∃

Page 124: Your data structures are made of maths!

(a, b,a b

Umpire

trait Umpire {def theA: A = adef someB: B = b

}

, )Instances

Page 125: Your data structures are made of maths!

(a, b,a b

Umpire

trait Umpire {def theA: A = adef someB: B = b

}

, )Instances

Page 126: Your data structures are made of maths!

(a, b,a b

Umpire

trait Umpire {def theA: A = adef someB: B = b

}

, )

not

actually

unique

Instances

Page 127: Your data structures are made of maths!

Requiring a unique arrow

from a 3rd object that

independently knows A

and B proves that there’s

no extra gunk.

Page 128: Your data structures are made of maths!

But wait!

Page 129: Your data structures are made of maths!

What if Umpire has

special knowledge about

other products?

Page 130: Your data structures are made of maths!

A × BA Bfirst seco

nd

Umpire

theA someB

trait Umpire {def theA: Adef someB: Bdef specialOtherProd: (A,B)

}

Page 131: Your data structures are made of maths!

It could introduce strange

new things with its special

knowledge!

Page 132: Your data structures are made of maths!

We need to know nothing

about the object other

than the two arrows!

Page 133: Your data structures are made of maths!

PA B

???

? ?unique∃

For all objects that 1) have an arrow to A and B

2) there exists a unique arrow to P

Page 134: Your data structures are made of maths!

PA B

???

? ?unique∃

Then P is “the” product of A and B!

Page 135: Your data structures are made of maths!

Same with

sums!

Page 136: Your data structures are made of maths!

SA B

???

? ?unique∃

For all objects that 1) have an arrow from A and B

2) there exists a unique arrow from S

Page 137: Your data structures are made of maths!

SA B

???

? ?unique∃

Then S is “the” sum of A and B!

Page 138: Your data structures are made of maths!

Terminology

universal property

universal mapping

propertyUMP

Page 139: Your data structures are made of maths!

Terminology

universal property

“The most efficient solution to a

problem”

Page 140: Your data structures are made of maths!

Terminology

universal property

Proves that

- We generate only what we need

- We depend on only what we need

Page 141: Your data structures are made of maths!

Compare to programming:

trait Monoid[M] {def id: Mdef compose(a: M, b: M): M

}

trait Foldable[F[_]] {def foldMap[M: Monoid, A](

fa: F[A], f: A => M): M}

Page 142: Your data structures are made of maths!

Like UMPs, type parameters

“for all F”

“for all A and M where M is a Monoid”

don’t just prove what your code is,

but what it isn’t.

Page 143: Your data structures are made of maths!

Proving what your code isn’t

prevents bloat and error, and

promotes reuse.

Proving what your code is allows

you to use it.

Page 144: Your data structures are made of maths!

Zero

On

eProduct

s

Sum

sExponent

s

Scala Algebra

(A, B)

0

1

AB

A+B

A -> B

A \/ B

Nothing

Unit

BA

Types vs Algebra vs CT

CT

?

?

?

?

? ?

Page 145: Your data structures are made of maths!

Intermission

Page 146: Your data structures are made of maths!

Injections

A B

A function is injective if it maps 1-to-1

onto a subset of the codomain

Page 147: Your data structures are made of maths!

A B

All the information in A is

preserved…

Page 148: Your data structures are made of maths!

A B

All the information in A is

preserved…

A

Page 149: Your data structures are made of maths!

B

But everything else in B is lost.

A B

Page 150: Your data structures are made of maths!

Another way of looking at it…

C A Bfg

h

If f ∘ g = f ∘ h, then g = h

Page 151: Your data structures are made of maths!

C A Bfg

h

If f ∘ g = f ∘ h, then g = h

Page 152: Your data structures are made of maths!

C A Bfg

h

If f ∘ g = f ∘ h, then g = h

Page 153: Your data structures are made of maths!

Injections in code

User(firstName = "Bob", lastName = "Smith", age = 73)

User JSON

{“firstName”: "Bob", “lastName”: ”Smith”, “age”: 73}

Page 154: Your data structures are made of maths!

User JSON

We don’t lose information converting

to JSON.

Page 155: Your data structures are made of maths!

But from JSON?

We lose structure…

User JSON

Page 156: Your data structures are made of maths!

Surjections

A B

A function is surjective if it maps

onto the whole of the codomain

Page 157: Your data structures are made of maths!

A

All the information in B is

preserved…

AB

Page 158: Your data structures are made of maths!

A

But everything else in A is lost.

AB

Page 159: Your data structures are made of maths!

A B C

If g ∘ f = h ∘ f, then g = h

f g

h

Page 160: Your data structures are made of maths!

A B C

f g

h

If g ∘ f = h ∘ f, then g = h

Page 161: Your data structures are made of maths!

A B C

f g

h

If g ∘ f = h ∘ f, then g = h

Page 162: Your data structures are made of maths!

Injections generalised

C A Bf

g

h

If f ∘ g = f ∘ h, then g = h

Page 163: Your data structures are made of maths!

Monomorphisms

C A Bf

g

h

f is monic

If f ∘ g = f ∘ h, then g = h

Page 164: Your data structures are made of maths!

Monomorphisms

C A Bf

g

h

If f ∘ g = f ∘ h, then g = h

Page 165: Your data structures are made of maths!

Surjections generalised

CA Bf

g

h

If g ∘ f = h ∘ f, then g = h

Page 166: Your data structures are made of maths!

Epimorphisms

CA Bf

g

h

f is epic

If g ∘ f = h ∘ f, then g = h

Page 167: Your data structures are made of maths!

C

A

B

A mono in C is an epi in Cop

A

B

C Cop

C

Page 168: Your data structures are made of maths!

Monos are dual to

epis.

Page 169: Your data structures are made of maths!

Bijections

A B

A function is bijective if it maps 1-to-1

onto the whole codomain

Page 170: Your data structures are made of maths!

Bijections

A B

We don’t lose any

information A B A…

A

Page 171: Your data structures are made of maths!

Bijections

B

Nor do we lose information

B A B…

A B

Page 172: Your data structures are made of maths!

The CT equivalent is of

course…

Page 173: Your data structures are made of maths!

The CT equivalent is of

course…

Isomorphisms!

Page 174: Your data structures are made of maths!

Injection Surjection Bijection

Mono Epi Iso

Page 175: Your data structures are made of maths!

Motivation

So much software is just mapping

between things!

Page 176: Your data structures are made of maths!

form

Page 177: Your data structures are made of maths!

form{…}

Page 178: Your data structures are made of maths!

form{…} Order(a,b,c)

Page 179: Your data structures are made of maths!

form{…} Order(a,b,c) INSERT INTO…

Page 180: Your data structures are made of maths!

form{…} Order(a,b,c) INSERT INTO…

Page 181: Your data structures are made of maths!

form{…} Order(a,b,c) INSERT INTO…

Receipt(…)

Page 182: Your data structures are made of maths!

form{…} Order(a,b,c) INSERT INTO…

Receipt(…)

Logs on disk

Page 183: Your data structures are made of maths!

form{…} Order(a,b,c) INSERT INTO…

Receipt(…)

Logs on disk

<xml>

Page 184: Your data structures are made of maths!

form{…} Order(a,b,c) INSERT INTO…

Receipt(…)<xml>receipt

Logs on disk

Page 185: Your data structures are made of maths!

It is essential to understand how

information is preserved in flows like

this

Page 186: Your data structures are made of maths!

Chinese

whispers!

Bugs proliferate where data is lost!

Page 187: Your data structures are made of maths!

Injections and surjections tell us

what is preserved and what is lost

Page 188: Your data structures are made of maths!

Bijections are especially valuable

Page 189: Your data structures are made of maths!

Conclusion

Data structures are

made out of maths!

Page 190: Your data structures are made of maths!

How we map between them

is maths too.

Page 191: Your data structures are made of maths!

Understanding the

underlying shape of data

and functions is enormously

helpful for more robust,

error-free software

Page 192: Your data structures are made of maths!

Isomorphism is more

interesting than

equality!

Isomorphic types can be

rewritten, optimised without

error.

Isomorphic mappings allow

us to preserve information

Page 193: Your data structures are made of maths!

Universal properties exemplify

• Depending on the minimum

• Producing the minimum

?

Page 194: Your data structures are made of maths!

Again, Category Theory

shows us deeper, simpler

patterns, unifying concepts

that otherwise look different

?

?

×

+

Page 195: Your data structures are made of maths!

Further readingAwodey, “Category Theory”

Lawvere & Schanuel, “Conceptual Mathematics: an introduction to categories”

Jeremy Kun, “Math ∩ Programming” at http://jeremykun.com/

Chris Taylor, “The algebra of algebraic datatypes”

http://chris-taylor.github.io/blog/2013/02/10/the-algebra-of-algebraic-data-types/

http://chris-taylor.github.io/blog/2013/02/11/the-algebra-of-algebraic-data-types-part-ii/

http://chris-taylor.github.io/blog/2013/02/13/the-algebra-of-algebraic-data-types-part-iii/

Page 196: Your data structures are made of maths!

Further readingBartosz Milewski “Categories for Programmers”

http://bartoszmilewski.com/2014/10/28/category-theory-for-

programmers-the-preface/

http://bartoszmilewski.com/2015/03/13/function-types/