## Categories

In addition to categories of data structures and their homomorphisms, there are other simple constructions that give rise to categories from other ones:

• By currying the hom functor, we get the notion of a “slice category”.
```var slice = function (y) {
return function (x) {
return hom([x], y);
};
};
```

The objects in the slice category `Contract/y` are functions whose result passes the contract `y`; the morphisms from `f:x1 -> y` to `g:x2 -> y` are functions `h:x1 -> x2` such that `f(x) = g(h(x))`.

• `Contract²` is the category whose objects are pairs of contracts and whose morphisms are pairs of functions.
• Functors and natural transformations form a category.
• Given a monad `myMonad = monadOf(myFunctor)`, there’s a category whose objects are contracts and whose morphisms are functions of the form `f:x -> myFunctor(y)`. To compose `f:x -> myFunctor(y)` and `g:y -> myFunctor(z)`, we write

`function (x) { return myMonad['*'](myFunctor(g)(f(x))); }`.

This is how the register function works in the Parser monad example.

• Given any functor myFunctor, we get a category whose objects are algebras of the functor—i.e. a contract `c` and a function `h:myFunctor(c) -> c`—and whose morphisms are functions `f:c1 -> c2` such that

`h2(myFunctor(f)(x)) === f(h1(x))`.

I’ll go into more detail on these in future posts.