Abstract
The development of programming languages can be quite complicated and costly. Hence, much effort has been devoted to the modular definition of language features that can be reused in various combinations to define new languages and experiment with their semantics. A notable outcome of these efforts is the algebra-based “datatypes à la carte” (DTC) approach. When combined with algebraic effects, DTC can model a wide range of common language features. Unfortunately, the current state of the art does not cover modular definitions of advanced control-flow mechanisms that defer execution to an appropriate point, such as call-by-name and call-by-need evaluation, as well as (multi-)staging.
This paper defines latent effects, a generic class of such control-flow mechanisms. We demonstrate how function abstractions, lazy computations and a MetaML-like staging can all be expressed in a modular fashion using latent effects, and how they can be combined in various ways to obtain complex semantics. We provide a full Haskell implementation of our effects and handlers with a range of examples.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 1.
- 2.
The function
is short for \( fmap \circ const \).
- 3.
References
Atkey, R., Johann, P.: Interleaving data and effects. J. Funct. Program. 25 (2015)
van den Berg, B., Schrijvers, T., Bach-Poulsen, C., Wu, N.: Latent effects for reusable language components: extended version (2021)
Filinski, A.: Representing layered monads. In: 26th Symposium on Principles of Programming Languages, POPL 1999, pp. 175–188 (1999)
Forster, Y., Kammar, O., Lindley, S., Pretnar, M.: On the expressive power of user-defined effects: effect handlers, monadic reflection, delimited control. J. Funct. Program. 29, e15 (2019)
Garcia, R., Lumsdaine, A., Sabry, A.: Lazy evaluation and delimited control. Log. Methods Comput. Sci. 6(3) (2010)
Hyland, M., Plotkin, G., Power, J.: Combining effects: sum and tensor. Theoret. Comput. Sci. 357(1–3), 70–99 (2006)
Jaskelioff, M.: Monatron: an extensible monad transformer library. In: Scholz, S.-B., Chitil, O. (eds.) IFL 2008. LNCS, vol. 5836, pp. 233–248. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-24452-0_13
Kiselyov, O., Ishii, H.: Freer monads, more extensible effects. In: 8th Symposium on Haskell, pp. 94–105. ACM (2015)
Leijen, D.: Type directed compilation of row-typed algebraic effects. In: 44th Symposium on Principles of Programming Languages, pp. 486–499. ACM (2017)
Levy, P.B.: Call-by-push-value: decomposing call-by-value and call-by-name. High. Order Symb. Comput. 19(4), 377–414 (2006)
Liang, S., Hudak, P., Jones, M.: Monad transformers and modular interpreters. In: Symposium on Principles of Programming Languages, pp. 333–343. ACM (1995)
Lindley, S., McBride, C., McLaughlin, C.: Do be do be do. In: 44th Symposium on Principles of Programming Languages. ACM (2017)
Moggi, E.: An abstract view of programming languages. Technical report ECS-LFCS-90-113, Edinburgh University, Department of Computer Science, June 1989
Piróg, M., Schrijvers, T., Wu, N., Jaskelioff, M.: Syntax and semantics for operations with scopes. In: Logic in Computer Science, pp. 809–818. ACM (2018)
Piróg, M., Wu, N., Gibbons, J.: Modules over monads and their algebras. In: 6th Conference on Algebra and Coalgebra in Computer Science. LIPIcs, vol. 35, pp. 290–303. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2015)
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). https://doi.org/10.1007/3-540-45931-6_24
Plotkin, G.D., Power, J.: Algebraic operations and generic effects. Appl. Categ. Struct. 11(1), 69–94 (2003)
Plotkin, G., Pretnar, M.: Handlers of algebraic effects. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 80–94. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-00590-9_7
Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In: Generative Programming and Component Engineering, pp. 127–136. ACM (2010)
Schrijvers, T., Piróg, M., Wu, N., Jaskelioff, M.: Monad transformers and modular algebraic effects: what binds them together. In: 12th International Symposium on Haskell, pp. 98–113. ACM (2019)
Schuster, P., Brachthäuser, J.I., Ostermann, K.: Compiling effect handlers in capability-passing style. Proc. ACM Program. Lang. 4(ICFP), 93:1–93:28 (2020)
Sheard, T., Jones, S.L.P.: Template meta-programming for Haskell. ACM SIGPLAN Not. 37(12), 60–75 (2002)
Swierstra, W.: Data types à la carte. J. Funct. Program. 18(4), 423–436 (2008)
Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. In: PEPM, pp. 203–217 (1997)
Taha, W., Sheard, T.: MetaML and multi-stage programming with explicit annotations. Theor. Comput. Sci. 248(1), 211–242 (2000). PEPM 1997
Wadler, P.: The expression problem. Mailing list (1998)
Wei, G., Bračevac, O., Tan, S., Rompf, T.: Compiling symbolic execution with staging and algebraic effects. Proc. ACM Program. Lang. 4(OOPSLA) (2020)
Wu, N., Schrijvers, T.: Fusion for free. In: Hinze, R., Voigtländer, J. (eds.) MPC 2015. LNCS, vol. 9129, pp. 302–322. Springer, Cham (2015). https://doi.org/10.1007/978-3-319-19797-5_15
Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Symposium on Haskell, pp. 1–12. ACM (2014)
Yallop, J.: Staged generic programming. Proc. ACM Program. Lang. 1(ICFP), 29:1–29:29 (2017)
Acknowledgments
This work has been supported by EPSRC grant number EP/S028129/1 on ‘Scoped Contextual Operations and Effects’, by the NWO VENI project on ‘Composable and Safe-by-Construction Programming Language Definitions’ (VI.Veni.192.259), by FWO project G095917N, and by KU Leuven project C14/20/079.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2021 Springer Nature Switzerland AG
About this paper
Cite this paper
van den Berg, B., Schrijvers, T., Poulsen, C.B., Wu, N. (2021). Latent Effects for Reusable Language Components. In: Oh, H. (eds) Programming Languages and Systems. APLAS 2021. Lecture Notes in Computer Science(), vol 13008. Springer, Cham. https://doi.org/10.1007/978-3-030-89051-3_11
Download citation
DOI: https://doi.org/10.1007/978-3-030-89051-3_11
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-89050-6
Online ISBN: 978-3-030-89051-3
eBook Packages: Computer ScienceComputer Science (R0)