Skip to main content

2019 | OriginalPaper | Buchkapitel

Towards Optic-Based Algebraic Theories: The Case of Lenses

verfasst von : J. López-González, Juan M. Serrano

Erschienen in: Trends in Functional Programming

Verlag: Springer International Publishing

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

Optics provide rich abstractions and composition patterns to access and manipulate immutable data structures. However, the state of real applications is mostly handled through databases, caches, web services, etc. In this effectful setting, the usefulness of optics is severely limited, whereas algebraic theories, thanks to their potential to abstract away from particular infrastructures, shine. Unfortunately, there is a severe lack of standard algebraic theories, e.g. like MonadState, that programmers can reuse to avoid writing their domain repositories from scratch. This paper argues that optics can serve as a fruitful metaphor to design a rich catalogue of state-based algebraic theories, and focuses on the paradigmatic case of lenses. It shows how lenses can be generalised into an algebraic theory; how compositionality of these algebraic theories can be founded on lens composition; and how to exploit the resulting abstractions in the modular design of data layers. The paper systematically uses Coq for all its definitions and proofs.

Sie haben noch keine Lizenz? Dann Informieren Sie sich jetzt über unsere Produkte:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Anhänge
Nur mit Berechtigung zugänglich
Fußnoten
1
Coq will be used throughout the paper.
 
2
For the moment, we will ignore the details about lens representations.
 
3
We could also have defined accessors to update the name or departments with a new value passed as parameter, but they are not used in the upcoming examples.
 
4
We assume familiarity with monads. You can find the particular Coq encoding that we use for https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figao_HTML.gif in the supplementary material (Sect. A).
 
5
There exists a polymorphic lens version which is more general, where https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figaz_HTML.gif declares a different type for the part, leading to a different type for the resulting whole.
 
6
If we discard https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figbb_HTML.gif , we can talk about well-behaved lenses.
 
7
We represent https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figcj_HTML.gif as https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figck_HTML.gif to simplify signatures.
 
8
Here, we assume that https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figef_HTML.gif also collects a https://static-content.springer.com/image/chp%3A10.1007%2F978-3-030-18506-0_4/MediaObjects/482829_1_En_4_Figeg_HTML.gif evidence.
 
9
Note that this would only involve the math department in the new configuration.
 
Literatur
1.
Zurück zum Zitat Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for bi-directional tree transformations: a linguistic approach to the view update problem. ACM SIGPLAN Not. 40(1), 233–246 (2005)CrossRef Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for bi-directional tree transformations: a linguistic approach to the view update problem. ACM SIGPLAN Not. 40(1), 233–246 (2005)CrossRef
2.
Zurück zum Zitat O’Connor, R.: Functor is to lens as applicative is to biplate: introducing multiplate. In: 7th ACM SIGPLAN Workshop on Generic Programming. ACM (2011) O’Connor, R.: Functor is to lens as applicative is to biplate: introducing multiplate. In: 7th ACM SIGPLAN Workshop on Generic Programming. ACM (2011)
4.
Zurück zum Zitat Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad hoc. In: Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 60–76. ACM (1989) Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad hoc. In: Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 60–76. ACM (1989)
5.
Zurück zum Zitat Van Deursen, A., Klint, P., Visser, J.: Domain-specific languages: an annotated bibliography. ACM SIGPLAN Not. 35(6), 26–36 (2000)CrossRef Van Deursen, A., Klint, P., Visser, J.: Domain-specific languages: an annotated bibliography. ACM SIGPLAN Not. 35(6), 26–36 (2000)CrossRef
8.
Zurück zum Zitat Cheney, J., McKinna, J., Stevens, P., Gibbons, J., Abou, F., et al.: Entangled state monads. In: BX Workshop (2014) Cheney, J., McKinna, J., Stevens, P., Gibbons, J., Abou, F., et al.: Entangled state monads. In: BX Workshop (2014)
9.
Zurück zum Zitat Pickering, M., Wu, N., Gibbons, J.: Profunctor optics: modular data accessors. Art Sci. Eng. Program. 1(2) (2017) Pickering, M., Wu, N., Gibbons, J.: Profunctor optics: modular data accessors. Art Sci. Eng. Program. 1(2) (2017)
12.
Zurück zum Zitat Shkaravska, O.: Side-effect monad, its equational theory and applications. Arvutiteaduse teooriaseminar (2005) Shkaravska, O.: Side-effect monad, its equational theory and applications. Arvutiteaduse teooriaseminar (2005)
14.
Zurück zum Zitat Johnson, M., Rosebrugh, R.: Lens put-put laws: monotonic and mixed. Electr. Commun. EASST 49 (2012) Johnson, M., Rosebrugh, R.: Lens put-put laws: monotonic and mixed. Electr. Commun. EASST 49 (2012)
15.
Zurück zum Zitat Cheney, J., Lindley, S., Wadler, P.: A practical theory of language-integrated query. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, New York, NY, USA, pp. 403–416. ACM (2013) Cheney, J., Lindley, S., Wadler, P.: A practical theory of language-integrated query. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, New York, NY, USA, pp. 403–416. ACM (2013)
16.
Zurück zum Zitat Suzuki, K., Kiselyov, O., Kameyama, Y.: Finally, safely-extensible and efficient language-integrated query. In: Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, New York, NY, USA, pp. 37–48. ACM (2016) Suzuki, K., Kiselyov, O., Kameyama, Y.: Finally, safely-extensible and efficient language-integrated query. In: Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, New York, NY, USA, pp. 37–48. ACM (2016)
17.
Zurück zum Zitat Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. ACM SIGPLAN Not. 46, 127–136 (2010)CrossRef Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. ACM SIGPLAN Not. 46, 127–136 (2010)CrossRef
18.
Zurück zum Zitat Moors, A., Rompf, T., Haller, P., Odersky, M.: Scala-virtualized. In: Proceedings of the ACM SIGPLAN 2012 Workshop on Partial Evaluation and Program Manipulation, pp. 117–120. ACM (2012) Moors, A., Rompf, T., Haller, P., Odersky, M.: Scala-virtualized. In: Proceedings of the ACM SIGPLAN 2012 Workshop on Partial Evaluation and Program Manipulation, pp. 117–120. ACM (2012)
Metadaten
Titel
Towards Optic-Based Algebraic Theories: The Case of Lenses
verfasst von
J. López-González
Juan M. Serrano
Copyright-Jahr
2019
DOI
https://doi.org/10.1007/978-3-030-18506-0_4