为什么从根本上讲,遍历遍历定义在应用程序上?
最近,我一直在“将所有内容蒸馏到其基本面”中,而且我一直找不到明确的理论原因来定义可穿越的类型类型,只有实用性的,”在适用的山地上,许多数据类型都可以做到这一点,并有很多提示。
我知道有一个适用的“家庭”,如 https://duplode.github.io/posts/divisible-and-the-monoidal-quartet.html 。
我还知道,虽然可遍历遍历是适用的膜结构,但“半群”中的遍历1个类型术语描述了应用煤膜,而“分布式”中的分布式类型描述了函数代数。
此外,我知道可折叠,可折叠1和理论上的折叠家庭成员可以描述可以使用单体,半群和相应的单型家庭成员(例如岩浆(作为二进制树折叠)和每种折叠版本(用于折叠)的数据类型,每种杂物(用于折叠)(用于折叠为每个版本的无序版本)。
因此,由于可遍历是可折叠的子类,因此我认为它本质上是单的,同样,我认为traversable1本质上是半群,并且分布式本质上是共同体(如其在“分布式”软件包中的描述中提到的)。
这感觉就像是正确的轨道,但是应用和申请来自这里?是否有岩浆和可交换版本?类别中有一个非平凡性共素的类别的分布式家庭吗?
是“这些类型层是否存在,它们是什么?如果没有?
class FoldableMagma t => TraversableMagma t where
traverseMagma :: ??? f => (a -> f b) -> (t a -> f (t b))
class FoldableCommute t => TraversableCommute t where
traverseCommute :: ??? f => (a -> f b) -> (t a -> f (t b))
class Foldable t => ContraTraversable t where
contraTraverse :: Divisible f => (b -> f a) -> (t a -> f (t b))
-- im really not sure on this last one
-- but it's how i'd expect an endofunctor over coalgebras to look
-- which seems potentially related to traversables?
本质上,我的问题 ”> https://hackage.haskage.haskage.org/package/package/data-functor-logistic
href =“ https://hackage.haskell.org/package/package/data-functor-logistic” rel =“ nofollow noreferrer 描述了偶性函数的分布式版本 - 是否可以在除外分(或决策)上等效地遍历?
I've been on a bit of a "distilling everything to its fundamentals" kick lately, and I've been unable to find clear theoretical reasons for how the Traversable typeclass is defined, only practical ones of "it's useful to be able to traverse over applicative coalgebras, and lots of datatypes can do it" and a whole lot of hints.
I'm aware that there's an applicative "family", as described by https://duplode.github.io/posts/divisible-and-the-monoidal-quartet.html.
I'm also aware that while Traversable traversals are applicative coalgebras, the Traversable1 typeclass from 'semigroupoids' describes apply coalgebras, and the Distributive typeclass from 'distributive' describes functor algebras.
Additionally, I'm aware that Foldable, Foldable1, and theoretical fold family members, describe datatypes that can be folded using monoids, semigroups, and corresponding monoid family members such as magmas (for folding as a binary tree) and commutative versions of each (for folding as unordered versions of each).
As such, as Traversable is a subclass of Foldable, I assume it's monoidal in nature, and similarly I assume Traversable1 is semigroupal in nature, and Distributive is comonoidal in nature (as mentioned in its description in the 'distributive' package).
This feels like the right track, but where do Applicative and Apply come from here? Are there magmatic and commutative versions? Would there be a distributive family in a category with non-trivial comonoids?
Essentially, my question is "do these typeclasses exist, and what are they? if not, why not?":
class FoldableMagma t => TraversableMagma t where
traverseMagma :: ??? f => (a -> f b) -> (t a -> f (t b))
class FoldableCommute t => TraversableCommute t where
traverseCommute :: ??? f => (a -> f b) -> (t a -> f (t b))
class Foldable t => ContraTraversable t where
contraTraverse :: Divisible f => (b -> f a) -> (t a -> f (t b))
-- im really not sure on this last one
-- but it's how i'd expect an endofunctor over coalgebras to look
-- which seems potentially related to traversables?
Presumably less important bonus question: while attempting to research this, I came across the 'data-functor-logistic' package https://hackage.haskell.org/package/data-functor-logistic
This describes a version of Distributive over contravariant functors - is there an equivalent Traversable over Divisibles (or Decidables)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有任何实现这些课程的库,但是我会尝试揭开这些课程所代表的内容。我是程序员,而不是类别理论家,因此请与一粒盐一起服用。
应用
变体applymagma
applymagma
类具有与apply
类完全相同的方法,但不需要遵循协会法。如果
应用
类似于半群,则applymagma
类似于岩浆。applyCommute
applyCommute类将等同于申请类,但具有以下通勤定律:
如果
apply
apply> applycommute 类似于类似的交换性半群。traversable1
变体traversable1magma
a
traversable1magma
可以看作是traversable1
,提供了有关结构的更多信息。折叠1
类具有tononEmpty
方法,而折叠1MAGMA
类可以具有tobinarytree
方法。traversable1 -commute
a
traversable1commute
可以看作是traverable1
,而无需定义的订购元素。如果它不需要ORD A
约束,则set
来自容器
可能是此类的一个实例。 traversable1commute可能是遍历1的超级类别。请注意,这些是
traversable1
的变体,因为applymagma
not applyCommute 具有等同于pure
的函数。Contratrableable
Contratraversable
没有任何实例。要查看原因,请查看contratraverse
函数的类型。我们可以对以下内容进行专业化:
这是以下内容:
使用
const
和conquer
conquer 函数,这使我们能够创建任何类型的值,是不可能的。I'm not aware of any library that implements those classes, but I'll try to unravel what those classes would represent. I am a programmer, not a category theorist, so take this with a grain of salt.
Applicative
variantsApplyMagma
The
ApplyMagma
class has exactly the same methods as theApply
class, but it doesn't need to follow the associativity law.If
Apply
is analogous to semigroups,ApplyMagma
is analogous to magmas.ApplyCommute
The ApplyCommute class will be equivalent to the Apply class but with the following commutativity law:
If
Apply
is analogous to semigroups,ApplyCommute
is analogous to commutative semigroups.Traversable1
variantsTraversable1Magma
A
Traversable1Magma
can be seen as aTraversable1
with more information provided about the structure. While theFoldable1
class has atoNonEmpty
method, TheFoldable1Magma
class could have atoBinaryTree
method.Traversable1Commute
A
Traversable1Commute
can be seen as aTraversable1
without a defined ordering to the elements. If it didn't require anOrd a
constraint,Set
fromcontainers
could be an instance of this class. Traversable1Commute could be a superclass of Traversable1.Note that these are variants of
Traversable1
because neitherApplyMagma
norApplyCommute
have a function equivalent topure
.ContraTraversable
ContraTraversable
does not have any instances. To see why, look at the type of thecontraTraverse
function.We can specialize this to the following:
Which is eqivalent to the following:
Using
const
and theconquer
function from Divisible, this allows us to create a value of any type, which is impossible.自从问这个并收到以前的(出色的)答案以来,我已经了解了使用应用程序的另一个原因:代数数据类型!
如果没有任何约束,它只能描述无人居住的数据类型,例如:
如果它是函子,它可以描述看起来像这样的代数数据类型:
本质上,它是任何具有任意的(可能是无限的,如果在Haskell中描述的)的数据类型单个ftraversable参数的构造函数(其中
a
〜身份a
)。这就是说,任何可穿越的f a
都是(f(f(),a)
,作者函数的同构。引入应用程序启用额外的数据类型如下:
现在,只要它的有限数量大于零!同构现在是
(f(),nonepty a)
,它们的大小相等。应用启用以下内容:
现在允许空构造函数!同构现在为
(f(),[a])
。假设的交换性应用程序将用于交换代数数据类型,如果它们是一件事情 - 也许,如果设置仅与交换性单体可折叠,它们将是相关的!但是据我所知,通勤数据类型并不是Haskell的核心部分,因此这种形式的遍历不会显示代数数据类型。
分布式相似,它用任意许多记录(潜在无限)的单个构造函数描述函子。
据我所知,逻辑与这种代数解释无关 - 由于读取器函数通常与Distribunives一起用于创建Getter函数的集合,因此Logistic旨在与OP Contravariant functor合作,以创建Setter函数的集合。
这向我表明,由于作者函数的特征是其与
(a,r)是同构的,因此,由于作者函数的表征是其相反的(
)。(r,a)
)Since asking this and receiving the previous (excellent) answer, I have learnt another reason why Applicative is used: algebraic datatypes!
Without any constraint, it can only describe uninhabited datatypes, like this:
If it were Functor, it could describe algebraic datatypes that look something like these:
Essentially, it's any datatype with an arbitrary (potentially infinite, if that were describable in Haskell) number of constructors of a single FTraversable argument (where
a
~Identity a
). This is saying that any Traversablef a
is isomorphic to(f (), a)
, the Writer functor.Introducing Apply enables extra datatypes like the following:
Now constructors can have arbitrarily many arguments, as long as it's a finite number greater than zero! The isomorphism is now to
(f (), NonEmpty a)
, where they are of equal sizes.Applicative enables the following:
Now empty constructors are allowed! The isomorphism is now to
(f (), [a])
.A hypothetical commutative Applicative would be used for commutative algebraic datatypes, were they a thing - perhaps, if Set enforced that it were only foldable with commutative monoids, they would be relevant! But to my knowledge, commutative datatypes are not a core part of Haskell, and so this form of traversal will not show up for algebraic datatypes.
Distributive is similar, it describes functors with a single constructor of arbitrarily many records (potentially infinite).
Logistic is unrelated to this algebraic interpretation, to my knowledge - since the Reader functor is commonly used with Distributives to create a collection of getter functions, Logistic is designed to work with the Op contravariant functor to create a collection of setter functions.
This suggests to me that the equivalent for Traversable doesn't exist, due to the Writer functor that characterises Traversables being its own opposite (
(r,a)
is isomorphic to(a,r)
).