# Category Theory

• Objects
• Morphisms (maps between objects that preserve structure… but what “structure” means is a bit fuzzy! Just the “other stuff” about the object, the connections). Go from source to target.
• It talks about the relationship between objects, not the objects themselves. (And syntactic sugar)

In more detail…

• Objects are sets
• Morphisms are functions on sets
• Structure: membership, cardinality (size). Beyond cardinality, sets are maximally unstructured.

An example…

Category: MAN (manifolds)

• Objects: smooth manifold
• Morphism: smooth map
• Structure: calculus

Category: VECT (finite-dimensional vect. spaces over real)

• Objects: Finite dimensional vector space
• Morphism: Linear maps
• Structure: linearity

Interesting. Basically, we are describing the RULES we are implicitly operating in. “Vectors, what sport are they playing?”

Analogy: sports! Sport theory… set up players, rules, etc. Or games: set up objects, rules between them, you have your game. See what example we have. Are these games in the Poker category? (Then hold 'em, etc. … Omaha, etc.). Why is this useful? See hidden structure/relationships between these games. Make your own poker game?

Common language to organize types of mathematical ontologies.

• Structure: [needs to characterize this category] … Cartesian closed?

Category might not exist in a mathematical sense, but it exists in a Haskell sense. (Foundationally valid doesn’t matter… conveying something meaningful through language.)

Aside: Types and spaces are basically the same thing. (Mathematicians like spaces, types are new, but you can essentially convert them.)

Analogy: Soccer and hockey are basically the same thing! Similar rules, can we see that similar structure?

Note: One type and no types are the same (T :: T -> T). Everything is from one type back to that type. There’s one object, and a bunch of maps from that object back to itself. [Q: The syntax is we have type T, which has a map which goes from T back to T].

C = LISP / Clojure types

C = CAT (category)

• Object: categories
• Morphisms: Functor. [A structure-preserving map between categories]. It sends objects to objects, and morphisms to morphisms. Remember that morphisms have a source and target. After being changed, it must go to the same source and target.

@ 50:00 – the diagram has 3 points. There are implicit identity morphisms. And the paths could be equal (or not) if you go A-B-C or A-C directly.

Flowchart:

• Objects: Nodes
• Morphisms: Paths between nodes

Have a functor (in his words: “representation”)

Diagrams and categories correspond (objects and arrows/morphisms between them…)

Category theory a lingua franca for math. Interesting… way to describe other parts of math to each other. Imagine sports: how do you describe a new sport or game to someone else?

Category theory is more a social/communication benefit vs. a logical benefit…

Functions are first-class citizens (can be treated as objects). 2-morphisms, where morphisms are themselves objects that are changed. Morphisms of morphisms.

Database schema are categories. Heck, people can be categories (loved ones are objects, paths/genealogy are morphisms)

Main trickiness with Category Theory is the complex notation. (right?)

One intuition: conceptually, we understand an object by its action on all other objects, or by the actions of all objects on it.

We understand things by their relationship. Probe the object with other things.

Category theory for JS:

• Contracts [objects] & Guarded functions [morphism]. [together, form a category]

Guarded function is the arrow that moves a contract to a contract.

“Given any two contracts, a function that accepts as input the values that pass 1st contract, and produce value that pass 2nd contract”. Specify the source contract and the target contract

morphism takes a value that agrees to a contract, and returns a value that agrees to a contract.

functor: if you hand it a contract, handles array of contract… but can also modify a morphism? (hrm…)

• acts on both objects and morphisms. Produces new objects, and new morphisms.
• Make a diagram showing what’s happening. the tricky thing here is even the objects are functions. The morphism is a function that modifies a function.

Nice presentation: http://homepages.inf.ed.ac.uk/jcheney/presentations/ct4d1.pdf

• “Category theory helps organize thought” and identify patterns. [I like the analogy of looking at 2 sports, breaking it into players + rules, and seeing what overlap there is. Soccer and hockey are almost the same thing. Put the _____ (ball/puck) into a net only using your _____ (foot / stick).

http://johnbender.us/2012/02/29/faster-javascript-through-category-theory/

• We have a type called “html.morphism” which is a function with a specific signature [HTML in, HTML out]

• We can have another function [compose] which is html.morphism, html.morphism -> html.morphism, that is, it takes 2 functions [with a well-known signature] and returns a function [with a specific signature]. Treat a function with a specific signature as a type.

• Associativity… main idea is that you keep the order the same but move the parens around. Maybe you want to compute near the end first, then work your way backward or forward through the list.

# Great post. You should flesh this out add it to the main site. This is a hot topic. If I were you I would also discuss:

• Natural Transformations
• The Yoneda Lemma
• Kan Extensions
• Cartesian Closed Categories
• The Curry-Howard-Lembek correspondence
• N-Categories

If you can make these things simple and intuitive. It would be a remarkable accomplishment. (Future best seller? Better Explained: Category Theory )

Thanks Simon! Hoping to get deeper into this one :). I’d love to do have BE: Foo series for all the topics that have been bugging me…