所有的Haskell函子都是enduncunctors吗? [英] Are all Haskell functors endofunctors?

查看:52
本文介绍了所有的Haskell函子都是enduncunctors吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑,需要有人将我摆平.让我们概述一下我目前的理解:

I'm a bit confused, and need someone to set me straight. Lets outline my current understanding:

其中E是endofunctor,而A是某种类别:

Where E is an endofunctor, and A is some category:

E : A -> A.

由于Haskell中的所有类型和词素都属于Hask类别,因此Haskell中的 functor 也是 endofunctor 吗? F : Hask -> Hask.

Since all types and morphisms in Haskell are in the Hask category, is not any functor in Haskell also an endofunctor? F : Hask -> Hask.

我很高兴自己错了,并且以某种方式简化了这个过程,我希望有人告诉我我是个白痴.谢谢.

I have a good feeling that I'm wrong, and oversimplifying this somehow, and I'd like someone to tell me what an idiot I am. Thanks.

推荐答案

您可能想弄清楚您是在询问"Haskell中的函数"还是Functor.在Haskell中使用类别理论术语时,并不总是确定要假定哪个类别.

You may want to clarify whether you're asking about "functors in Haskell", or Functors. It's not always clear what category is being assumed when Category Theory terms are used in Haskell.

但是,是的,默认假设为 Hask ,该假设被视为Haskell类型的范畴,其功能为态射.在这种情况下, Hask 上的endofunctor F将把任何类型A映射到类型F(A),并且将两个类型A和B之间的任何函数 f 映射到函数F( f )在某些F(A)和F(B)类型之间.

But yes, the default assumption is Hask, which is taken to be the category of Haskell types with functions as morphisms. In that case, an endofunctor F on Hask would map any type A to a type F(A) and any function f between two types A and B to a function F(f) between some types F(A) and F(B).

如果我们然后仅将那些将任何类型a映射到类型(f a)的endofunctors(其中f是类型为* -> *的类型构造函数),则可以将函数的关联映射描述为类型为(a -> b) -> (f a -> f b)的高阶函数,它当然是称为Functor的类型类.

If we then limit ourselves to only those endofunctors which map any type a to a type (f a) where f is a type constructor with kind * -> *, then we can describe the associated map for functions as a higher-order function with type (a -> b) -> (f a -> f b), which is of course the type class called Functor.

但是,人们可以轻松地想象 Hask 上行为良好的endofunctors,它们不能(直接)作为Functor的实例编写,例如将类型a映射到的函子Either a t.虽然从 Hask 到完全其他某个类别的函子显然没有多大意义,但考虑从 Hask Hask op .

However, one can easily imagine well-behaved endofunctors on Hask which can't be written (directly) as an instance of Functor, such as a functor mapping a type a to Either a t. And while there's obviously not much sense in a functor from Hask to some other category entirely, it's reasonable to consider a (contravariant) functor from Hask to Haskop.

除此之外,Functor的实例必须从整个类别 Hask 映射到其某些子集,从而也形成一个类别.但是谈论 Hask 的子集之间的 函子也是合理的.例如,考虑一个将类型Maybe a发送到[a]的函子.

Beyond that, instances of Functor necessarily map from the entire category Hask onto some subset of it that, thus, also forms a category. But it's also reasonable to talk about functors between subsets of Hask. For instance, consider a functor that sends types Maybe a to [a].

您可能希望仔细阅读 category-extras软件包,该软件包提供了一些类别理论- Hask 中嵌入的灵感结构,而不是假设其全部.

You may wish to peruse the category-extras package, which provides some Category Theory-inspired structures embedded within Hask instead of assuming the entirety of it.

这篇关于所有的Haskell函子都是enduncunctors吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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