# What are functors in category theory?

## What are functors in category theory?

A Functor is kind of mapping of objects and morphisms that preserves composition and identity. We have two Categories: A and B . In Category A we have two objects a and b with morphism f . Our Functor is a mapping of objects a and b to Fa and Fb and mapping of morphisms, in this case single morphism: f to Ff .

## What is monad and monoid?

@AlexanderBelopolsky, technically, a monad is a monoid in the monoidal category of endofunctors equipped with functor composition as its product. In contrast, classical “algebraic monoids” are monoids in the monoidal category of sets equipped with the cartesian product as its product.

The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error.

The function pure is the second method required by the Applicative type class. The pure method is a useful helper function for taking an ordinary value or function and putting it into a context. The best way to understand pure is to play around with it in GHCi.

All told, a monad in X is just a monoid in the category of endofunctors of X, with product × replaced by composition of endofunctors and unit set by the identity endofunctor.

### What is an endofunctor on X?

X here is a category. Endofunctors are functors from a category to itself (which is usually all Functor s as far as functional programmers are concerned, since they’re mostly dealing with just one category; the category of types – but I digress). But you could imagine another category which is the category of “endofunctors on X “.

What is the unit object of the endofunctor category?

The endofunctor category is a strict monoidal category, thanks to our ability to compose endofunctors: The unit object of this monoidal category is the identity functor from CC to itself: Monoids. A monoid in this endofunctor category is called a monad on CC.

Is the endofunctor a monoidal category?

The endofunctor category is a strict monoidal category, thanks to our ability to compose endofunctors:

#### What are the morphisms of endofunctors?

F: C o C, and the morphisms are natural transformation between such endofunctors. The endofunctor category is a strict monoidal category, thanks to our ability to compose endofunctors: