127 research outputs found
Applicative Bidirectional Programming with Lenses
A bidirectional transformation is a pair of mappings between source and view data objects, one in each direction. When the view is modified, the source is updated accordingly with respect to some laws. One way to reduce the development and maintenance effort of bidirectional transformations is to have specialized languages in which the resulting programs are bidirectional by construction---giving rise to the paradigm of bidirectional programming.
In this paper, we develop a framework for applicative-style and higher-order bidirectional programming, in which we can write bidirectional transformations as unidirectional programs in standard functional languages, opening up access to the bundle of language features previously only available to conventional unidirectional languages. Our framework essentially bridges two very different approaches of bidirectional programming, namely the lens framework and Voigtlander’s semantic bidirectionalization, creating a new programming style that is able to bag benefits from both
A Representation Theorem for Second-Order Functionals
Representation theorems relate seemingly complex objects to concrete, more
tractable ones.
In this paper, we take advantage of the abstraction power of category theory
and provide a general representation theorem for a wide class of second-order
functionals which are polymorphic over a class of functors. Types polymorphic
over a class of functors are easily representable in languages such as Haskell,
but are difficult to analyse and reason about. The concrete representation
provided by the theorem is easier to analyse, but it might not be as convenient
to implement. Therefore, depending on the task at hand, the change of
representation may prove valuable in one direction or the other.
We showcase the usefulness of the representation theorem with a range of
examples. Concretely, we show how the representation theorem can be used to
show that traversable functors are finitary containers, how parameterised
coalgebras relate to very well-behaved lenses, and how algebraic effects might
be implemented in a functional language
Composing bidirectional programs monadically
Software frequently converts data from one representation to another and vice versa. Naively specifying both conversion directions separately is error prone and introduces conceptual duplication. Instead, bidirectional programming techniques allow programs to be written which can be interpreted in both directions. However, these techniques often employ unfamiliar programming idioms via restricted, specialised combinator libraries. Instead, we introduce a framework for composing bidirectional programs monadically, enabling bidirectional programming with familiar abstractions in functional languages such as Haskell. We demonstrate the generality of our approach applied to parsers/printers, lenses, and generators/predicates. We show how to leverage compositionality and equational reasoning for the verification of round-tripping properties for such monadic bidirectional programs
Semantic Bidirectionalization Revisited
A bidirectional transformation is a pair of mappings between source and view data objects, one in each direction. When the view is modified, the source is updated accordingly with respect to some laws. Over the years, a lot of effort has been made to offer better language support for programming such transformations, essentially allowing the programmers to construct one mapping of the pair and have the other automatically generated.
As an alternative to creating specialized new languages, one can try to analyse and transform programs written in general purpose languages, and
"bidirectionalize" them. Among others, a technique termed as semantic bidirectionalization stands out in term of user-friendliness. The unidirectional program can be written using arbitrary language constructs, as long as the function is polymorphic and the language constructs respect parametricity. The free theorem that follows from the polymorphic type of the program allows a kind of forensic examination of the transformation, determining its effect without examining its implementation. This is convenient, in the sense that the programmer is not restricted to using a particular syntax; but it does require the transformation to be polymorphic.
In this paper, we revisit the idea of semantic bidirectionalization and reveal the elegant principles behind the current state-of-the-art techniques. Guided by the findings, we derive much simpler implementations that scale easily
- …