Skip to main content

2015 | OriginalPaper | Buchkapitel

Fusion for Free

Efficient Algebraic Effect Handlers

verfasst von : Nicolas Wu, Tom Schrijvers

Erschienen in: Mathematics of Program Construction

Verlag: Springer International Publishing

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

search-config
loading …

Abstract

Algebraic effect handlers are a recently popular approach for modelling side-effects that separates the syntax and semantics of effectful operations. The shape of syntax is captured by functors, and free monads over these functors denote syntax trees. The semantics is captured by algebras, and effect handlers pass these over the syntax trees to interpret them into a semantic domain.
This approach is inherently modular: different functors can be composed to make trees with richer structure. Such trees are interpreted by applying several handlers in sequence, each removing the syntactic constructs it recognizes. Unfortunately, the construction and traversal of intermediate trees is painfully inefficient and has hindered the adoption of the handler approach.
This paper explains how a sequence of handlers can be fused into one, so that multiple tree traversals can be reduced to a single one and no intermediate trees need to be allocated. At the heart of this optimization is keeping the notion of a free monad abstract, thus enabling a change of representation that opens up the possibility of fusion. We demonstrate how the ensuing code can be inlined at compile time to produce efficient handlers.

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!

Fußnoten
1
Yes, almost for free!
 
2
The typeclass constraints on \( m _{2}\) are different.
 
Literatur
1.
Zurück zum Zitat Atkey, R., Johann, P., Ghani, N., Jacobs, B.: Interleaving data and effects (2012) (Submitted for publication) Atkey, R., Johann, P., Ghani, N., Jacobs, B.: Interleaving data and effects (2012) (Submitted for publication)
2.
Zurück zum Zitat Burris, S., Sankappanavar, H.P.: A course in universal algebra, graduate texts in mathematics, vol. 78. Springer, New York (1981)MATH Burris, S., Sankappanavar, H.P.: A course in universal algebra, graduate texts in mathematics, vol. 78. Springer, New York (1981)MATH
3.
Zurück zum Zitat Chin, W.N.: Safe fusion of functional expressions ii: Further improvements. J. Funct. Program. 4, 515–555 (1994)CrossRef Chin, W.N.: Safe fusion of functional expressions ii: Further improvements. J. Funct. Program. 4, 515–555 (1994)CrossRef
4.
Zurück zum Zitat Gill, A., Launchbury, J., Peyton Jones, S.L.: A short cut to deforestation. In: Proceedings of the Conference on Functional Programming Languages and Computer Architecture, FPCA 1993, pp. 223–232. ACM, New York, NY, USA (1993) Gill, A., Launchbury, J., Peyton Jones, S.L.: A short cut to deforestation. In: Proceedings of the Conference on Functional Programming Languages and Computer Architecture, FPCA 1993, pp. 223–232. ACM, New York, NY, USA (1993)
5.
Zurück zum Zitat Harper, T.: A library writer’s guide to shortcut fusion. In: Proceedings of the 4th ACM Symposium on Haskell, Haskell 2011, pp. 47–58. ACM, New York, NY, USA (2011) Harper, T.: A library writer’s guide to shortcut fusion. In: Proceedings of the 4th ACM Symposium on Haskell, Haskell 2011, pp. 47–58. ACM, New York, NY, USA (2011)
6.
Zurück zum Zitat Hinze, R., Harper, T., James, D.W.H.: Theory and practice of fusion. In: Hage, J., Morazán, M.T. (eds.) IFL. LNCS, vol. 6647, pp. 19–37. Springer, Heidelberg (2011) CrossRef Hinze, R., Harper, T., James, D.W.H.: Theory and practice of fusion. In: Hage, J., Morazán, M.T. (eds.) IFL. LNCS, vol. 6647, pp. 19–37. Springer, Heidelberg (2011) CrossRef
7.
Zurück zum Zitat Hinze, R., Wu, N., Gibbons, J.: Conjugate hylomorphisms - the mother of all structured recursion schemes. In: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, pp. 527–538. ACM, New York, NY, USA (2015) Hinze, R., Wu, N., Gibbons, J.: Conjugate hylomorphisms - the mother of all structured recursion schemes. In: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, pp. 527–538. ACM, New York, NY, USA (2015)
8.
9.
Zurück zum Zitat Kammar, O., Lindley, S., Oury, N.: Handlers in action. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional programming, ICFP 2014, pp. 145–158. ACM (2013) Kammar, O., Lindley, S., Oury, N.: Handlers in action. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional programming, ICFP 2014, pp. 145–158. ACM (2013)
10.
Zurück zum Zitat Kiselyov, O., Sabry, A., Swords, C.: Extensible effects: an alternative to monad transformers. In: Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Haskell 2013, pp. 59–70. ACM (2013) Kiselyov, O., Sabry, A., Swords, C.: Extensible effects: an alternative to monad transformers. In: Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Haskell 2013, pp. 59–70. ACM (2013)
11.
Zurück zum Zitat Liang, S., Hudak, P., Jones, M.: Monad transformers and modular interpreters. In: Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1995, pp. 333–343. ACM, New York, NY, USA (1995) Liang, S., Hudak, P., Jones, M.: Monad transformers and modular interpreters. In: Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1995, pp. 333–343. ACM, New York, NY, USA (1995)
12.
Zurück zum Zitat Ploeg, A.V.D., Kiselyov, O.: Reflection without remorse: revealing a hidden sequence to speed up monadic reflection. In: Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell 2014, pp. 133–144. ACM, New York, NY, USA (2014) Ploeg, A.V.D., Kiselyov, O.: Reflection without remorse: revealing a hidden sequence to speed up monadic reflection. In: Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell 2014, pp. 133–144. ACM, New York, NY, USA (2014)
14.
Zurück zum Zitat 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) CrossRefMATH 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) CrossRefMATH
15.
17.
Zurück zum Zitat Schrijvers, T., Wu, N., Desouter, B., Demoen, B.: Heuristics entwined with handlers combined. In: Proceedings of the 16th International Symposium on Principles and Practice of Declarative Programming, PPDP 2014, pp. 259–270. ACM (2014) Schrijvers, T., Wu, N., Desouter, B., Demoen, B.: Heuristics entwined with handlers combined. In: Proceedings of the 16th International Symposium on Principles and Practice of Declarative Programming, PPDP 2014, pp. 259–270. ACM (2014)
19.
Zurück zum Zitat Takano, A., Meijer, E.: Shortcut deforestation in calculational form. In: Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, FPCA 1995, pp. 306–313. ACM, New York, NY, USA (1995) Takano, A., Meijer, E.: Shortcut deforestation in calculational form. In: Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, FPCA 1995, pp. 306–313. ACM, New York, NY, USA (1995)
20.
Zurück zum Zitat Voigtländer, J.: Proving correctness via free theorems: the case of the destroy/build-rule. In: Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, PEPM 2008, pp. 13–20. ACM, New York, NY, USA (2008) Voigtländer, J.: Proving correctness via free theorems: the case of the destroy/build-rule. In: Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, PEPM 2008, pp. 13–20. ACM, New York, NY, USA (2008)
21.
Zurück zum Zitat Voigtländer, J.: Free theorems involving type constructor classes: functional pearl. In: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009, pp. 173–184. ACM, New York, NY, USA (2009) Voigtländer, J.: Free theorems involving type constructor classes: functional pearl. In: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009, pp. 173–184. ACM, New York, NY, USA (2009)
22.
Zurück zum Zitat Wadler, P.: Theorems for free!. In: Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, FPCA 1989, pp. 347–359. ACM, New York, NY, USA (1989) Wadler, P.: Theorems for free!. In: Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, FPCA 1989, pp. 347–359. ACM, New York, NY, USA (1989)
24.
Zurück zum Zitat Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell 2014, pp. 1–12. ACM, New York, NY, USA (2014) Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell 2014, pp. 1–12. ACM, New York, NY, USA (2014)
Metadaten
Titel
Fusion for Free
verfasst von
Nicolas Wu
Tom Schrijvers
Copyright-Jahr
2015
Verlag
Springer International Publishing
DOI
https://doi.org/10.1007/978-3-319-19797-5_15

Premium Partner