单子编程中的商:投射代数等价于余代数
Quotients in monadic programming: Projective algebras are equivalent to coalgebras
AI总结:
本文刻画了单子编程中自由代数的投射商,证明投射代数范畴等价于由单子分解诱导的余单子上的余代数范畴,从而为将多态商实现为余代数提供了新方法,并给出对偶的商类型族及相关单子性、余单子性推论。
摘要:
在单子编程中,数据类型被表示为自由代数,由数据值以及刻画某些计算效应的代数运算和方程生成。这些代数是自由的,即它们只满足其代数理论所施加的方程,而不受任何额外方程的约束。其后果是它们不允许商类型。这当然常常带来不便。每当计算涉及具有多个代表元的数据,并且需要根据某些并非所有数据都满足的方程将它们等同起来时,单子程序员就必须离开自由代数的范畴,转而求助于显式的析构器。我们刻画了这些析构器在所有运算下都被保持的情形,此时自由代数的商同时也是它们的子代数。这样的商被称为“投射的”。尽管投射代数在泛代数中很流行,但在单子环境中并未引起太多关注;在单子环境中它们展现出一种令人惊讶的化身:对于任意给定的单子,一个合适的投射代数范畴等价于由任何单子分解所诱导的余单子上的余代数范畴。对于单子程序员来说,这种等价提供了一种便捷的方式,将多态商实现为余代数。内射余代数与所有代数的对偶对应则引出了另一族商类型,它们似乎具有不同的应用领域。这两个等价还带来了若干关于单子性和余单子性的一般推论。
英文摘要:
In monadic programming, datatypes are presented as free algebras, generated by data values, and by the algebraic operations and equations capturing some computational effects. These algebras are free in the sense that they satisfy just the equations imposed by their algebraic theory, and remain free of any additional equations. The consequence is that they do not admit quotient types. This is, of course, often inconvenient. Whenever a computation involves data with multiple representatives, and they need to be identified according to some equations that are not satisfied by all data, the monadic programmer has to leave the universe of free algebras, and resort to explicit destructors. We characterize the situation when these destructors are preserved under all operations, and the resulting quotients of free algebras are also their subalgebras. Such quotients are called *projective*. Although popular in universal algebra, projective algebras did not attract much attention in the monadic setting, where they turn out to have a surprising avatar: for any given monad, a suitable category of projective algebras is equivalent with the category of coalgebras for the comonad induced by any monad resolution. For a monadic programmer, this equivalence provides a convenient way to implement polymorphic quotients as coalgebras. The dual correspondence of injective coalgebras and all algebras leads to a different family of quotient types, which seems to have a different family of applications. Both equivalences also entail several general corollaries concerning monadicity and comonadicity.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。