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 实现。