为什么要为 monad 定义单位自然变换——这不是由 monad 的定义暗示的吗?
- monad 被定义为类别 C 上的一个 endofunctor。比方说,C 具有类型 int 和 bool 以及其他构造类型作为对象。现在让我们考虑一下在此类别上定义的列表 monad。
根据它的定义,list 是一个 endofunctor,它将 int 类型映射(这可以解释为函数吗?)到 List[int] ,将 bool 映射到 List[bool] ,并映射(又是一个函数?)一个态射 int - >布尔到 列表[int] -> List[bool]
到目前为止,这还是有道理的。但让我陷入深深困惑的是随之而来的自然变换的额外定义: 一个。 Unit...将 int 转换为 List[int] (List 函子的定义不是已经暗示了这一点吗?这是我的一个主要困惑
b. List 函子是否总是必须被理解为从 int 到 List[ 的映射int] 不是从 int 到 List[bool]
c. 单位自然转换 int 到 List[int] 与将 List 定义为函子所暗示的映射不同吗?我之前的问题。
- A monad is defined as an endofunctor on category C. Let's say, C has type int and bool and other constructed types as objects. Now let's think about the list monad defined over this category.
By it's very definition list then is an endofunctor, it maps (can this be interpreted as a function?) an int type into List[int] and bool to List[bool] of and maps (again a function?) a morphism int -> bool to
List[int] -> List[bool]
So, far, it kind of makes sense. But what throws me into deep confusion is the additional definitions of natural transformations that need to accompany it:
a. Unit...that transforms int into List[int] (doesn't the definition of List functor already imply this? This is one major confusion I have
b. Does the List functor always have to be understood as mapping from int to List[int] not from int to List[bool]?
c. Is the unit natural transformation int to List[int] different from map from int to List[int] implied by defining List as a functor? I guess this is just re-statement of my earlier question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Unit 是从 C 上的 Identity 函子到 List 的自然变换;一般来说,自然变换 a: F =>两个并联函子F,G之间的G:X→ Y 由态射 a_x : Fx -> 组成
您应该将上述自然变换视为从 F“转到”G 的一种方式。将其应用于列表情况的单位,单位为每种类型 X 指定函数 Unit_X : X -> List[X],这只是将您的类型的实例视为具有一个元素的 List[X] 实例。
我不明白你在 b 上到底想问什么。但关于c。它们是完全不同的东西。定义中没有隐含从 int 到 List[int] 的映射;定义给出的是,对于每个映射 f: X -> Y,映射List(f):List[X] ->列表[Y]; Unit 为您提供了一种将任何类型 X 视为某种特定类型的 X 列表(具有一个元素)的方法。
希望有帮助;从您使用的 List[] 表示法来看,也许您有 Scala/Java 背景,如果是这种情况,您可能会发现 Scala 中类别理论的介绍很有趣:http://www.weiglewilczek.com/blog/?p=2760
Unit is a natural transformation from the Identity functor on C to List; in general, a natural transformation a: F => G between two parallel functors F,G : X -> Y consists of
you should thought of a natural transformation as above as a way of "going" from F to G. Applying this to your unit for List situation, Unit specifies for each type X a function Unit_X : X -> List[X], and this is just viewing instances of your type as List[X] instances with one element.
I don't understand what you're asking exactly on b. but with respect to c. they're completely different things. There is no map from int to List[int] implied at the definition; what the definition gives you is, for each map f: X -> Y, a map List(f) : List[X] -> List[Y]; what Unit gives you is a way of viewing any type X as some particular kind of Lists of X's, those with one element.
Hope it helps; from the List[] notation you use, maybe you come from a Scala/Java background, if this is the case you may find this intro to category theory in Scala interesting: http://www.weiglewilczek.com/blog/?p=2760
嗯,真正令人困惑的是,Cat A 和 Cat B 之间的函子 F 定义为:
映射:
这就是我对书中定义的看法。上面的第 1 点(F 将 A 映射到 F(A))——在我看来,这就像将 A 转换为 F(A) 的态射。如果是这样,为什么我们需要单位自然变换,从 A 到 F(A)?
非常奇怪的是,函子定义使用了“映射”一词(但没有使用“态射”一词)。我发现 A 到 F(A) 不称为态射,而是映射。
Well, what is really confusing is, functor F between Cat A and Cat B isdefined as:
a mapping:
This is how I see those as being defined in the books. Point #1 above (F maps A to F(A)) - that reads to me like a morphism to convert A into F(A). If that is the case, why do we need unit natural transformation, to go from A to F(A)?
What is very curious is that the functor definition uses the word map (but does not use the word morphism). I see that A to F(A) is not called a morphism but a map.