本文介绍了Haskell中的函子与范畴论中的函子有什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,函子是两个类别之间的映射,例如来自到其中和是类别.

For as far as I understand, a functor is a mapping between two categories, for example from objects in to objects in where and are categories.

在Haskell中,存在 Hask ,其中对象是Haskell类型,而态射是Haskell函数.但是,Functor类型类具有函数fmap,该函数在这些类型(因此是对象而不是类别本身)之间进行映射:

In Haskell there is Hask in which the objects are Haskell types and the morphisms are Haskell functions. However, the Functor type class has a function fmap which maps between these types (which are thus objects and not categories themselves):

fmap :: (a -> b) -> f a -> f b

f af b都是 Hask 中的对象.这是否意味着Haskell中Functor的每个实例都是一个endofunctor,如果不是,Functor确实代表一个仿函数吗?

f a and f b are both objects in Hask. Does this mean every instance of Functor in Haskell is an endofunctor, and if not does Functor really represent a functor?

我在这里想念什么?类型也是Haskell中的类别吗?

What am I missing here? Are types also categories in Haskell?

推荐答案

Functor的实例指定两件事:类型为* -> *的类型构造函数F,即从Hask对象到对象的映射Hask的函数和类型(a -> b) -> (F a -> F b)的函数,即从Hask的箭头到与对象映射F兼容的Hask的箭头的映射.因此,是的,所有Functor实例都是endofunctors.关于Hackage有几种概括,例如 Control.Categorical.Functor .

An instance of Functor specifies two things: a type constructor F of kind * -> *, that is, a mapping from objects of Hask to objects of Hask, and a function of type (a -> b) -> (F a -> F b), that is, a mapping from arrows of Hask to arrows of Hask compatible with the object-mapping F. So, yes, all instances of Functor are endofunctors. There are several generalizations available on Hackage, e.g. Control.Categorical.Functor.

这篇关于Haskell中的函子与范畴论中的函子有什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 07:25