Category Theory 2

In notebook:
FrontEndMasters Hardcore Functional
Created at:
2017-04-02
Updated:
2019-08-15
Tags:
Functional Programming JavaScript

Part II. The Voyage


  add(1,1) // 2
You will know exactly what this does. 
  1. associative (can group them in any order)
  2. commutative (the arguments can come in any order)
  3. identity (with a 0 argument it returns the the other argument)
  4. distributive (can use it in any other composition/function (with ​multiply​ for example)
Then shows that ​add​ can use any type of arguments, not just integers (strings, floats, arrays). 

You have intuitions and laws behind what ​add​ can do and it always holds (does what you think it should do). 

Category Theory

talks about ​compose​. The above laws apply to it as well. (Same as ​add​).

Talks about the type signature ​(b -> c)​ meaning a function that takes ​b​ and returns ​c​. (this is a Haskell type signature)

​compose :: (b -> c) -> (a -> b) -> (a -> c)

​id :: a -> a

You need a composition and an id function to create a category

The identity function (above, just gives back the same value)

Category Laws

Uses the ​identity​ function (​id​) below
  // left identity
compose(id, f) == f

// rigth identity
compose(f, id) == f

// associativity
compose(compose(f,g), h) == compose(f, compose(g,h))
Demoes on jsbin that since ​compose​ is associative, he can group the functions in any way he wants (and extract them). Just like ​add​