函子和自函子的区别 [英] Differences between functors and endofunctors

查看:24
本文介绍了函子和自函子的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能简单解释一下两者之间的区别吗?我没有完全理解 monad 是内函子而不是函子的部分.

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.

与内同态与态射相同.

那么,为什么 monad 必须是内函子?

Now, why must monads be endofunctors?

有一句名言Monads 只是属于内函子范畴的幺半群".幸运的是,其他人已经在在这个答案中很好地解释了这一点.

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.

monad 必须是内函子的关键是 join,在 Haskell 中被称为,或者 μ,在类别中通常被称为理论,是 monad 定义¹的一部分.现在

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

所以将函子 m 应用于一个对象的结果(在 Hask 中,Haskell 类型的范畴为对象,函数为态射,一个类型)必须是一个对象,m 可以再次应用于.这意味着它必须属于函子 m 的域的范畴.

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.

如果一个函子的域和余域相同[严格来说,如果它的余域是其域的一个子范畴],换句话说,如果它是一个内函子,那么函子只能与它自己组合.由于与自身的可组合性是 monad 定义的一部分,因此 monad 更重要的是内函子.

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.

¹ 一个定义,也可以使用 (>>=)bind 来定义一个 monad,并使用 join 作为派生财产.

¹ One definition, one can alternatively define a monad using (>>=) or bind and have join as a derived property.

这篇关于函子和自函子的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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