Recent Forum Posts
 From categories: All categories General Discussion on Bx Languages and Tools: Default Category

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
ltail⭨ xs (x:_) = x:xs