仿函数和endofunctors之间的差异 [英] Differences between functors and endofunctors

查看:119
本文介绍了仿函数和endofunctors之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以用简单的术语解释两者之间的区别吗?我并没有完全理解monad是endofunctors而不是functor的部分。

解决方案

仿函数可能会从一个类到一个不同的人,endofunctor是一个函子,其开始和目标类别是相同的。



与endomorphisms与态度相同。



现在,monads为什么必须是内部管理员?



有一句名言Monad在内部管理员类别中只是单身人士。幸运的是,其他人已经在这个答案中解释了



monad必须是endofunctor的关键是加入,因为它在Haskell中调用,或者μ,因为它通常在类别理论中被称为monad的定义的一部分。现在

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

所以应用函子 m 到一个对象(在Hask中,Haskell类型作为对象和作为态射的函数,一个类型)必须是可以再次应用 m 的对象。这意味着它必须属于仿函数 m 的域。



仿函数只能是如果它的域和共域是相同的[严格地说,如果它的共域是它的域的一个子类别],换句话说,如果它是一个endofunctor,它就与它自己组成。由于与自身的可组合性是monad定义的一部分,因此monad是管理员的一个较早的内部元素。

1一个定义,可以用(>> =)绑定,并将加入作为派生属性。

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.

解决方案

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.

这篇关于仿函数和endofunctors之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆