# Reflections on Monadic Lenses

## Abstract

Bidirectional transformations (bx) have primarily been modeled as pure functions, and do not account for the possibility of the side-effects that are available in most programming languages. Recently several formulations of bx that use monads to account for effects have been proposed, both among practitioners and in academic research. The combination of bx with effects turns out to be surprisingly subtle, leading to problems with some of these proposals and increasing the complexity of others. This paper reviews the proposals for monadic lenses to date, and offers some improved definitions, paying particular attention to the obstacles to naively adding monadic effects to existing definitions of pure bx such as lenses and symmetric lenses, and the subtleties of equivalence of symmetric bidirectional transformations in the presence of effects.

## Notes

### Acknowledgements

The work was supported by the UK EPSRC-funded project *A Theory of Least Change for Bidirectional Transformations* (TLCBX Project 2013–2016) (EP/K020218/1, EP/K020919/1).

## Supplementary material

## References

- Abou-Saleh, F., Cheney, J., Gibbons, J., McKinna, J., Stevens, P.: Notions of bidirectional computation and entangled state monads. In: Hinze, R., Voigtländer, J. (eds.) MPC 2015. LNCS, vol. 9129, pp. 187–214. Springer, Heidelberg (2015a)Google Scholar
- Abou-Saleh, F., McKinna, J., Gibbons, J.: Coalgebraic aspects of bidirectional computation. In: BX 2015, CEUR-WS, vol. 1396, pp. 15–30 (2015b)Google Scholar
- Cheney, J., McKinna, J., Stevens, P., Gibbons, J., Abou-Saleh, F.: Entangled state monads. In: Terwilliger and Hidaka (2014)Google Scholar
- Diviánszky, P.: LGtk API correction. http://people.inf.elte.hu/divip/LGtk/CorrectedAPI.html
- Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for bidirectional tree transformations: a linguistic approach to the view-update problem. TOPLAS
**29**(3), 17 (2007)CrossRefGoogle Scholar - Foster, N., Matsuda, K., Voigtländer, J.: Three complementary approaches to bidirectional programming. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 1–46. Springer, Heidelberg (2012)CrossRefGoogle Scholar
- Hofmann, M., Pierce, B.C., Wagner, D.: Symmetric lenses. In: POPL, pp. 371–384. ACM (2011)Google Scholar
- Johnson, M., Rosebrugh, R.: Spans of lenses. In: Terwilliger and Hidaka (2014)Google Scholar
- Jones, M.P., Duponcheel, L.: Composing monads. Technical report RR-1004, DCS, Yale (1993)Google Scholar
- King, D.J., Wadler, P.: Combining monads. In: Proceedings of the 1992 Glasgow Workshop on Functional Programming, pp. 134–143 (1992)Google Scholar
- Liang, S., Hudak, P., Jones, M.P.: Monad transformers and modular interpreters. In: POPL, pp. 333–343 (1995)Google Scholar
- Pacheco, H., Hu, Z., Fischer, S.: Monadic combinators for “putback” style bidirectional programming. In: PEPM, pp. 39–50. ACM (2014). http://doi.acm.org/10.1145/2543728.2543737
- Plotkin, G., Power, J.: Notions of computation determine monads. In: Nielsen, M., Engberg, U. (eds.) FOSSACS 2002. LNCS, vol. 2303, pp. 342–356. Springer, Heidelberg (2002)CrossRefGoogle Scholar
- Stevens, P.: Bidirectional model transformations in QVT: Semantic issues and open questions. SoSyM
**9**(1), 7–20 (2010)Google Scholar - Terwilliger, J., Hidaka, S. (eds.): BX Workshop (2014). http://ceur-ws.org/Vol-1133/#bx
- TLCBX Project: a theory of least change for bidirectional transformations (2013–2016). http://www.cs.ox.ac.uk/projects/tlcbx/, http://groups.inf.ed.ac.uk/bx/
- Wadler, P.: Comprehending monads. Math. Struct. Comput. Sci.
**2**(4), 461–493 (1992). http://dx.org/10.1017/S0960129500001560 MathSciNetCrossRefMATHGoogle Scholar - Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 24–52. Springer, Heidelberg (1995)CrossRefGoogle Scholar