问题描述
不久前我问了这个问题.关于以下箭头法则:
I asked this question a while ago. It was about the following arrow law:
arr fst . first f = f . arr fst -- (.) :: Category k => k b c -> k a b -> k a c
在帖子 Asad Saeeduddin 下的评论中,它以自然转化的方式对其进行了解释. >.我想检查一下我的理解是否正确,并将其与 Bartosz Milewski的进行比较有关自然转化的文章.
In the comments under the post Asad Saeeduddin explained it in terms of natural transformations. I would like to check whether I got their explanation right and compare it a bit to Bartosz Milewski's article on natural transformations.
因此,自然变换的定义是:
我们有两个类别C
和D
和函子F, G : C ~> D
.自然变换α
是D
中的一族箭头,例如:
We have two categories C
and D
and functors F, G : C ~> D
. A natural transformation α
is a family of arrows in D
such that:
- 这些箭头从
F
的结果转到G
的结果.也就是说,对于C
中的每个对象a
,都有一个箭头(在a
处称为α
的组件)α_a :: F a ~> G a
. - 对于每个
f :: a ~> b
,a
和b
作为C
中的对象,保持:Gf . α_a = α_b . Ff
.那是自然.
- These arrows go from the results of
F
to the results ofG
. That is, for every objecta
inC
there exists an arrow (called the component ofα
ata
)α_a :: F a ~> G a
. - For every
f :: a ~> b
,a
andb
being objects inC
, holds:Gf . α_a = α_b . Ff
. That is the naturality.
基本上,我们需要弄清楚我们的情况中有四个变量:C
,D
,F
和G
.
Basically, we need to figure what four variables are in our case: C
, D
, F
and G
.
据我所知:
-
C
和D
是任意类型的同一类别,其中k a b
是其中的箭头,其中k
是我们正在使用的Arrow
实例.因此,F
和G
是终结符.
C
andD
are the same category of arbitrary types,k a b
being arrows in it, wherek
is theArrow
instance we are working with. Therefore,F
andG
are endofunctors.
F
是(, c)
,G
是Identity
.换句话说,如果我们不再使用类型,则将F
与first
映射,将G
与id
映射. 不可能更容易地根据类型进行思考,因为Category
和Arrow
类可帮助我们构造类别的箭头,而不是对象
F
is (, c)
and G
is Identity
. In other words, if we no longer work with types, we map F
with first
and G
with id
. It would probably be easier NOT to think in terms of types as the Category
and Arrow
classes help us construct category's arrows, not objects
这是对的吗
此外, Bartosz Milewski写下了这些想法像这样:
fmap f . alpha = alpha . fmap f
据我所知,我们需要一种更通用的形式来实现我们的目的,因为alpha :: forall a. F a -> G a
在这里仅针对其适用的类别来处理 Hask .还是我错了? fmap
在这张照片中有哪个地方?
As far as I get it, we need a more general form for our purposes as here alpha :: forall a. F a -> G a
deals with Hask only as the category it works with. Or am I wrong? Which place does fmap
have in this picture?
推荐答案
您无需担心额外的类别,因为arr fst
并不涉及任意的Arrow
,只需涉及它的(,)
实例即可.
You don't need to worry about extra categories, because arr fst
doesn't involve an arbitrary Arrow
, just the (,)
instance of it.
在Haskell中,某些函子f
和c
的类型为f a -> g a
的函数是自然转换.对于arr fst :: (b -> c) -> (b, c)
,让f ~ (->) b
和g ~ (,) b
.
In Haskell, a function of type f a -> g a
for some functors f
and c
is a natural transformation. In the case of arr fst :: (b -> c) -> (b, c)
, let f ~ (->) b
and g ~ (,) b
.
这篇关于"arr fst"如何自然转变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!