Can someone explain in simple terms the difference between the two? I’m not fully understanding the part where monads are endofunctors versus being just functors.
Can someone explain in simple terms the difference between the two? I’m not fully
Share
A functor may go from one category to a different one, an endofunctor is a functor for which start and target category are the same.
Same as with endomorphisms versus morphisms.
Now, why must monads be endofunctors?
There is the famous quote that “Monads are just monoids in the category of endofunctors”. Fortunately, somebody else has already explained that rather well in this answer.
The key point why a monad has to be an endofunctor, is that
join, as it is called in Haskell, orµ, as it is usually called in category theory, is part of the definition¹ of a monad. Nowso the result of applying the functor
mto an object (in Hask, the category of Haskell types as objects and functions as morphisms, a type) must be an object thatmcan again be applied to. That means it must belong to the category that is the domain of the functorm.A functor can only be composed with itself if its domain and codomain are the same [strictly, if its codomain is a subcategory of its domain], in other words, if it is an endofunctor. Since composability with itself is part of the definition of a monad, monads are a fortiori endofunctors.
¹ One definition, one can alternatively define a monad using
(>>=)orbindand havejoinas a derived property.