Home Category Basics
Post
Cancel

Category Basics

It seems inevitable that, after one learned Haskell, there’s a good possibility she will become a victim of category theory. This is a series(hopefully) of notes about category theory.

Category Theory is the theory using formal method to study the semantics of cats a language that is spoken by mathematicians, just like Design Pattern is a language spoken by senior software engineers. Of course, the latter one reads less exotic and sometimes harmful.

Definition of Category

768px-Category_SVG.svg.png (768×768) (wikimedia.org)

A category C consists of:

  • A collection of objects, Ob(C);

  • A collection of morphisms(arrows), Mor(C);
    • For each morphism(arrow) f, a domain object A and a codomain object B. f:AB and dom(f)=A,cod(f)=B.
    • The collection of morphisms(arrows) between two objects: domain A and codomain B, is denoted as Hom(A,B).
  • A binary operator called composition, satisfying:
    • For any pair of arrows f:AB and g:BC, an arrow gf:AC.
    • (Associativity) For any f:AB,g:BC,h:CD, we have h(gf)=(hg)f.
    • (Identity) For each object A, an identity arrow idA, such that for any arrow f, idAf=f=fidA.

Examples of Category

  1. Set
    • Objects: sets, A.

    • Arrows: total functions, f:AB.
    • Composition: function composition.
  2. Poset
    • Objects: partially-ordered sets, (P,).
      • P is a set.
      • is a reflexive, transitive, antisymmetric relation on P.
    • Arrows: total order-preserving functions, f:PQ, such that p,pP.pPpf(p)Qf(p).
    • Composition: function composition.
  3. Mon
    • Objects: monoids, (M,).
      • M is a set.
      • is an associative binary operator on M.
      • an identity element eM such that mM.em=m=me.
    • Arrows: monoid homomorphisms, f:MN, such that m,mM.mMm=f(m)Nf(m) and f(eM)=eN.
    • Composition: homomorphism composition.
  4. Grp
    • Objects: group, (G,)
      • G is a set.
      • is an associative binary operator.
      • an identity element eG such that gG.ge=g=eg.
      • inverse: gG.g1G.gg1=e=g1g.
    • Arrows: group homomorphisms, f:GH, such that g,gG.gGg=f(g)Hf(g), f(eM)=eN
    • Composition: homomorphism composition.
  5. Ω-Alg
    • Objects: Ω-Algebras, (|A|,a).
      • |A| is a set called carrier.
      • a:ωΩ|A|ar(ω)|A| is an interpretation.
        • Ω is a set of operator (signature).
        • ar(ω) is the arity of ω.
    • Arrows: Ω-homomorphisms, h:|A||B|, such that ωΩ.h(a(x1,...,xar(ω)))=b(h(x1),...,h(xar(ω))).
    • Composition: homomorphism composition.

More examples:

  • Categorical Logic

    • Objects: formulas, A.

    • Arrows: proofs, f:AB.

    • Composition: transitivity of implication. f:ABg:BCgf:AC

  • Functional Programming Language
    • Objects: types, T.
    • Arrows: functions, f:TU
    • Composition: function composition
  • Dual Category Cop of C
    • Objects: Ob(C)
    • Arrows: opposite of arrows in C.
      • f:AB from C, we have fop:BA in Cop
    • Composition: trivial.
  • Product category C×D
    • Objects: objects pairs (A,B) where A is a C-object and B is a D-object.
    • Arrows: arrows pairs (f,g) where f is a C-arrow and g is an D-arrow.
    • Composition: pairwise composition, (f,g)(h,i)=(fh,gi).
  • Subcategory B of C
    • Objects: each B-object in is a C-object
    • Arrows: for all B-objects B and B, HomB(B,B)HomC(B,B)
    • Composition: same as C

Commutative Diagrams

Definition

A diagram in a category C is a collection of vertices and directed edges, consistently labeled with objects and arrows of C.

A diagram is said to commute if for every pair of objects X,Y, all the paths from X to Y are equal.

Example

CommutativeDiagramExample.png

This diagram commutes:

  • In the inner left squre: mg=Gl
  • In the inner right squre: rh=Hm
  • In the outer rectangle: rhg=HGl
Make a donation if you like the post!
This post is licensed under CC BY 4.0 by the author.

A Simple REPL For the IMP Language

Morphisms and Objects

Comments powered by Disqus.