[Haskell-cafe] Relating functors in Category Theory to Functor

David Menendez zednenem at psualum.com
Mon Jun 28 23:44:53 EDT 2004


Until recently, I've had difficulty relating the concept of a "functor"
from Category Theory to the class Functor in Haskell. I've figured out a
relationship that seems to make sense, but I wanted to check with the
list to make sure I'm not on the wrong track.

In Category Theory, a functor F between categories C and D has two
parts:
    (1) a mapping F[ob] from the objects of C to the objects of D 
    (2) a mapping F[mor] from the morphisms of C to the morphisms of D 

For any morphism f: a -> b in C, there is a morphism F(f): F(a) -> F(b)
in D. For two morphisms f and g in C, F(f . g) = F(f) . F(g) in D.


We can interpret Haskell as a category with types as objects and
functions as morphisms. For example, isDigit :: Char -> Bool.

So, for some Functor f, the type constructor f corresponds to F[ob], and
fmap to F[mor]. For any function g :: a -> b, fmap g :: f a -> f b, and
fmap (g . h) = fmap g . fmap h.

--

For two functors F, G: C -> D, there is a natural transformation tau
from F to G, if for every object a in C, there is morphism tau[a]: F(a)
-> G(a) in D.


In Haskell, natural transformations are polymorphic functions, tau :: f
a -> g a. For example, maybeToList :: Maybe a -> [a].

--

A monad is a functor, F: C -> C, plus two natural transformations mu:
F^2 -> F and eta: I -> F (I being the identity functor for C).


In Haskell, F[ob] becomes the type constructor, F[mor] becomes fmap (or
liftM), mu becomes join :: f (f a) -> f a, and eta becomes return :: a
-> f a.


So, am I on the right track here?
-- 
David Menendez <zednenem at psualum.com> <http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list