Optics are bidirectional data accessors that capture data transformation patterns such as accessing subfields or iterating over containers. Profunctor optics are a particular choice of representation supporting modularity, meaning that we can construct accessors for complex structures by combining simpler ones. Profunctor optics have previously been studied only in an unenriched and non-mixed setting, in which both directions of access are modelled in the same category. However, functional programming languages are arguably better described by enriched categories; and we have found that some structures in the literature are actually mixed optics, with access directions modelled in different categories. Our work generalizes a classic result by Pastro and Street on Tambara theory and uses it to describe mixed V-enriched profunctor optics and to endow them with V-category structure. We provide some original families of optics and derivations, including an elementary one for traversals. Finally, we discuss a Haskell implementation.
翻译:Optics是一种双向数据访问器,能够捕获数据转换模式,例如访问子字段或遍历容器。Profunctor Optics是一种支持模块化的特定表示方式,使我们能够通过组合简单访问器来构造复杂结构的访问器。此前,Profunctor Optics仅在非富化且非混合的设定下被研究,其中访问的两个方向在同一范畴中建模。然而,函数式编程语言更适合用富化范畴来描述;并且我们发现文献中的某些结构实际上是混合Optics,其访问方向在不同的范畴中建模。我们的工作推广了Pastro与Street关于Tambara理论的经典结果,并将其用于描述混合V-富化Profunctor Optics,同时赋予它们V-范畴结构。我们提供了一些原创的Optics族及其推导过程,包括针对遍历的初等形式。最后,我们讨论了Haskell实现。