Hostname: page-component-586b7cd67f-dlnhk Total loading time: 0 Render date: 2024-12-02T18:41:23.144Z Has data issue: false hasContentIssue false

Generalized monoidal effects and handlers

Published online by Cambridge University Press:  28 July 2020

RUBEN P. PIETERS
Affiliation:
KU Leuven, Leuven, Belgium, (e-mail: ruben.pieters@cs.kuleuven.be)
EXEQUIEL RIVAS
Affiliation:
Inria, Paris, France, (e-mail: exequiel.rivas-gadda@inria.fr)
TOM SCHRIJVERS
Affiliation:
KU Leuven, Leuven, Belgium, (e-mail: tom.schrijvers@cs.kuleuven.be)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Algebraic effects and handlers are a convenient method for structuring monadic effects with primitive effectful operations and separating the syntax from the interpretation of these operations. However, the scope of conventional handlers is limited as not all side effects are monadic in nature. This paper generalizes the notion of algebraic effects and handlers from monads to generalized monoids, which notably covers applicative functors and arrows as well as monads. For this purpose, we switch the category theoretical basis from free algebras to free monoids. In addition, we show how lax monoidal functors enable the reuse of handlers and programs across different computation classes, for example, handling applicative computations with monadic handlers. We motivate and present these handler interfaces in the context of build systems. Tasks in a build system are represented by a free computation and their interpretation as a handler. This use case is based on the work of Mokhov et al. [(2018). PACMPL2(ICFP), 79:1–79:29.].

Type
Research Article
Copyright
© Cambridge University Press 2020

References

Bauer, A. & Pretnar, M. (2015) Programming with algebraic effects and handlers. J. Log. Algebr. Meth. Program. 84(1), 108123.CrossRefGoogle Scholar
Brady, E. (2013) Programming and reasoning with algebraic effects and dependent types. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming. ICFP ’13. New York, NY, USA: ACM, pp. 133144.CrossRefGoogle Scholar
Capriotti, P. & Kaposi, A. (2014) Free applicative functors. In Proceedings 5th Workshop on Mathematically Structured Functional Programming, MSFP@ETAPS 2014, Grenoble, France, 12 April 2014, pp. 230.CrossRefGoogle Scholar
Feldman, S. I. (1979) Make-a program for maintaining computer programs. Softw., Pract. Exper. 9(4), 255265.CrossRefGoogle Scholar
Gibbons, J. (2016) Free delivery (functional pearl). In Proceedings of the 9th International Symposium on Haskell. ACM, pp. 4550.CrossRefGoogle Scholar
Hughes, J. (2000) Generalising monads to arrows. Sci. Comput. Program. 37(1–3), 67111.CrossRefGoogle Scholar
Street, Jane. (2018) Dune: A Composable Build System. Available at: https://github.com/ocaml/duneGoogle Scholar
Jaskelioff, M. & O’Connor, R. (2015) A representation theorem for second-order functionals. J. Funct. Program. 25, e13.CrossRefGoogle Scholar
Kiselyov, O. & Ishii, H. (2015) Freer monads, more extensible effects. In Proceedings of the 8th ACM SIGPLAN Symposium on Haskell, Haskell 2015, Vancouver, BC, Canada, September 3–4, 2015, pp. 94105.CrossRefGoogle Scholar
Leijen, D. (2017) Type directed compilation of row-typed algebraic effects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18–20, 2017, pp. 486499.CrossRefGoogle Scholar
Lindley, S. (2013) Free idioms and free arrows in Haskell. Available at: https://github.com/slindley/dependent-haskell/tree/master/FreeGoogle Scholar
Lindley, S. (2014) Algebraic effects and effect handlers for idioms and arrows. In Proceedings of the 10th ACM SIGPLAN Workshop on Generic Programming. WGP 2014. New York, NY, USA: ACM, pp. 4758.CrossRefGoogle Scholar
Lindley, S., Wadler, P. & Yallop, J. (2011) Idioms are oblivious, arrows are meticulous, monads are promiscuous. Electron. Notes Theor. Comput. Sci. 229(5), 97117.CrossRefGoogle Scholar
Lindley, S., McBride, C. & McLaughlin, C. (2017) Do be do be do. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. POPL 2017. New York, NY, USA: ACM, pp. 500514.CrossRefGoogle Scholar
Marlow, S., Peyton Jones, S., Kmett, E. & Mokhov, A. (2016) Desugaring Haskell’s do-notation into applicative operations. In Proceedings of the 9th International Symposium on Haskell. Haskell 2016. New York, NY, USA: ACM, pp. 92104.CrossRefGoogle Scholar
McBride, C. & Paterson, R. (2008) Applicative programming with effects. J. Funct. Program. 18(1), 113.CrossRefGoogle Scholar
Mitchell, N. (2012) Shake before building: Replacing make with Haskell. In Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming. ICFP ’12. New York, NY, USA: ACM, pp. 5566.CrossRefGoogle Scholar
Moggi, E. (1991) Notions of computation and monads. Inf. Comput. 93(1), 5592.CrossRefGoogle Scholar
Mokhov, A., Mitchell, N. & Peyton Jones, S. (2018) Build systems à la carte. PACMPL 2(ICFP), 79:179:29.Google Scholar
Mokhov, A., Lukyanov, G., Marlow, S. & Dimino, J. (2019) Selective applicative functors. PACMPL 3(ICFP), 90:190:29.Google Scholar
O’Connor, R. (2014) Van Laarhoven free monad. http://r6.ca/blog/20140210T181244Z.htmlGoogle Scholar
Pastro, C. & Street, R. (2007) Doubles for monoidal categories. Theor. Appl. Categ. 21(11), 6175.Google Scholar
Paterson, R. (2001) A new notation for arrows. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming. ICFP ’01. New York, NY, USA: ACM, pp. 229240.CrossRefGoogle Scholar
Pieters, R. P., Schrijvers, T. & Rivas, E. (2017) Handlers for non-monadic computations. In Proceedings of the 29th Symposium on the Implementation and Application of Functional Programming Languages. IFL 2017. New York, NY, USA: ACM, pp. 4:1–4:11.CrossRefGoogle Scholar
Plotkin, G. & Pretnar, M. (2009) Handlers of algebraic effects. In Programming Languages and Systems, 18th European Symposium on Programming, ESOP 2009, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2009, York, UK, March 22–29, 2009. Proceedings, pp. 8094.CrossRefGoogle Scholar
Rivas, E. (2018) Relating idioms, arrows and monads from monoidal adjunctions. In Proceedings of the 7th Workshop on Mathematically Structured Functional Programming, MSFP@FSCD 2018, Oxford, UK, 8th July 2018, pp. 1833.CrossRefGoogle Scholar
Rivas, E. & Jaskelioff, M. (2017) Notions of computation as monoids. J. Funct. Program. 27, e21.CrossRefGoogle Scholar
Rivas, E., Jaskelioff, M. & Schrijvers, T. (2015) From monoids to nearsemirings: The essence of MonadPlus and Alternative. In Proceedings of the 17th International Symposium on Principles and Practice of Declarative Programming. PPDP 2015, Falaschi, M. & Albert, E. (eds). ACM, pp. 196207.Google Scholar
Wadler, P. (1990) Comprehending monads. Proceedings of the 1990 ACM Conference on LISP and Functional Programming. LFP 1990. New York, NY, USA: ACM, pp. 6178.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.