一句话:证明单子编程中投射代数范畴等价于单子分解所诱导余代数的范畴,从而可用余代数实现多态商类型。
在单子编程中,数据类型常被表示为自由代数,只满足代数理论提供的操作与方程,因而没有商类型;若需按额外方程识别多个代表元,程序员只能使用显式析构函数。本文刻画这些析构函数在所有操作下保持、且自由代数的商同时为子代数的情况,称之为投射商。核心结果是:对任意单子,一个合适的投射代数范畴等价于由该单子的任意分解所诱导余单子的余代数范畴。该等价为单子程序员提供了用余代数实现多态商类型的便捷途径。对偶地,内射余代数与所有代数的对应产生另一族商类型及不同应用;两个等价还导出若干关于单子性与余单子性的推论。
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.