Recent Forum Posts
From categories:

Hi Jonathan,

I'm not sure what you mean by reversible, or inversion. In general, the "inverse" of a get is not unique — you typically have a choice of many puts that can all be equally "good". Bx frameworks try to hammer out what laws can be used to precisely say what "good" means.

I'm not from the PL/Haskell world but can still suggest [1] for a formal overview of the quite diverse "lens landscape". It might help you identify what you're interested in and provide relevant references and pointers for further reading.
From a more practical, hands-on side, I guess you might be interested in BiGUL [2], a relatively well-documented and mature Haskell library that can be used to easily program your example (and do much more).

The bx community is very diverse and we try hard (struggle?) to leverage this as an advantage. You might find our current bx benchmark interesting as it allows a direct comparison of the different bx approaches applied to the exact same example [3].

Cheers,
Tony

Bibliography
1. Michael Johnson, Robert D. Rosebrugh: Unifying Set-Based, Delta-Based and Edit-Based Lenses. Bx@ETAPS 2016: 1-13
2. Zhenjiang Hu, Hsiang-Shang Ko: Principles and Practice of Bidirectional Programming in BiGUL. Bidirectional Transformations - International Summer School, Oxford, UK, July 25-29, 2016, Tutorial Lectures, pages 100-150
3. Anthony Anjorin, Zinovy Diskin, Frédéric Jouault, Hsiang-Shang Ko, Erhan Leblebici, Bernhard Westfechtel: BenchmarX Reloaded: A Practical Benchmark Framework for Bidirectional Transformations. BX@ETAPS 2017: 15-30

How are you, ladies & gentlemen?

I'm interested in source-to-source program transformations, which I think should be reversible, implying monomorphism. To do this, one needs to be able to invert the components of these transformations, so I was happy to discover the idea of lenses, which plugged a hole in my mental compendium about a decade old.

Allow me to raise the very simple example of list decomposition, using Haskell notation. There's an obvious sense in which the inverse of the cons operation is pattern-matching on the the list head|tail, with the same notation, (:), used for both.1 Similarly, one can say that destructuring is "the same" as the (head⨯tail) joint operation. By another abuse of notation, in the form of entropy: $H(\text{<destructuring>}) = H(\mathtt{head}) + H(\mathtt{tail})$.

Now let me "lift" head and tail into the category of very well behaved (VWB?) lenses, which I'll call lhead and ltail, as

lhead⭧ = head
lhead⭨ x (_:xs) = x:xs

ltail⭧ = tail
ltail⭨ xs (x:_) = x:xs

where the Get operations are the original head and tail.2 Intuitively, the joint information provided by lhead|ltail is "the same" as that of cons plus pattern-matching, in that we could transform programs written in one syntactic convention into the other. There's probably a symmetric argument to show that a lensified cons has equivalent expressive power as well. If I were a category theorist, I might draw a little diagram.

Unfortunately, I'm asking questions on several topics, here, about which my knowledge level is abecedarian. Are there particular subcategories of lenses which show the algebraic behavior I'm suggesting? Is there a domain-theoretic way of describing the special relationship between lhead⭨, ltail⭨ and cons? I have the impression that some kind of higher-order functor should exist to map regular functions to these lenses.3 I hope someone will know what I'm talking about, even if I don't.

Thanks,
Jonathan J-S

Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.