Differences between functors and endofunctors

ぃ、小莉子 提交于 2019-11-28 16:40:12

问题


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.


回答1:


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. Now

Prelude Control.Monad> :t join
join :: Monad m => m (m a) -> m a

so the result of applying the functor m to an object (in Hask, the category of Haskell types as objects and functions as morphisms, a type) must be an object that m can again be applied to. That means it must belong to the category that is the domain of the functor m.

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 (>>=) or bind and have join as a derived property.



来源:https://stackoverflow.com/questions/10342876/differences-between-functors-and-endofunctors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!