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 contracty
; the morphisms fromf:x1 -> y
tog:x2 -> y
are functionsh:x1 -> x2
such thatf(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 formf:x -> myFunctor(y)
. To composef:x -> myFunctor(y)
andg:y -> myFunctor(z)
, we writefunction (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 functionh:myFunctor(c) -> c
—and whose morphisms are functionsf:c1 -> c2
such thath2(myFunctor(f)(x)) === f(h1(x))
.
I’ll go into more detail on these in future posts.
Advertisements
Leave a Reply