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仅在非丰富化且非混合的设定下被研究,即访问的两个方向在同一范畴中建模。然而,函数式编程语言更适宜通过丰富范畴来描述;且我们发现文献中的某些结构实为混合光学,其访问方向在不同范畴中建模。本研究推广了Pastro与Street关于Tambara理论的经典结论,用以描述混合的V-丰富化Profunctor Optics,并赋予其V-范畴结构。我们提出了若干原创的光学族与推导方法,包括针对遍历的初等方式。最后,讨论了一个Haskell实现。