Skip to main content

Latent Effects for Reusable Language Components

  • Conference paper
  • First Online:
Programming Languages and Systems (APLAS 2021)

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 64.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 84.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://github.com/birthevdb/Latent-Effect-and-Handlers.git.

  2. 2.

    The function is short for \( fmap \circ const \).

  3. 3.

    https://github.com/birthevdb/Latent-Effect-and-Handlers.git.

References

  1. Atkey, R., Johann, P.: Interleaving data and effects. J. Funct. Program. 25 (2015)

    Google Scholar 

  2. van den Berg, B., Schrijvers, T., Bach-Poulsen, C., Wu, N.: Latent effects for reusable language components: extended version (2021)

    Google Scholar 

  3. Filinski, A.: Representing layered monads. In: 26th Symposium on Principles of Programming Languages, POPL 1999, pp. 175–188 (1999)

    Google Scholar 

  4. 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)

    Google Scholar 

  5. Garcia, R., Lumsdaine, A., Sabry, A.: Lazy evaluation and delimited control. Log. Methods Comput. Sci. 6(3) (2010)

    Google Scholar 

  6. Hyland, M., Plotkin, G., Power, J.: Combining effects: sum and tensor. Theoret. Comput. Sci. 357(1–3), 70–99 (2006)

    Article  MathSciNet  Google Scholar 

  7. 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

    Chapter  Google Scholar 

  8. Kiselyov, O., Ishii, H.: Freer monads, more extensible effects. In: 8th Symposium on Haskell, pp. 94–105. ACM (2015)

    Google Scholar 

  9. Leijen, D.: Type directed compilation of row-typed algebraic effects. In: 44th Symposium on Principles of Programming Languages, pp. 486–499. ACM (2017)

    Google Scholar 

  10. Levy, P.B.: Call-by-push-value: decomposing call-by-value and call-by-name. High. Order Symb. Comput. 19(4), 377–414 (2006)

    Article  Google Scholar 

  11. Liang, S., Hudak, P., Jones, M.: Monad transformers and modular interpreters. In: Symposium on Principles of Programming Languages, pp. 333–343. ACM (1995)

    Google Scholar 

  12. Lindley, S., McBride, C., McLaughlin, C.: Do be do be do. In: 44th Symposium on Principles of Programming Languages. ACM (2017)

    Google Scholar 

  13. Moggi, E.: An abstract view of programming languages. Technical report ECS-LFCS-90-113, Edinburgh University, Department of Computer Science, June 1989

    Google Scholar 

  14. 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)

    Google Scholar 

  15. 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)

    Google Scholar 

  16. 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

    Chapter  MATH  Google Scholar 

  17. Plotkin, G.D., Power, J.: Algebraic operations and generic effects. Appl. Categ. Struct. 11(1), 69–94 (2003)

    Article  MathSciNet  Google Scholar 

  18. 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

    Chapter  Google Scholar 

  19. 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)

    Google Scholar 

  20. 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)

    Google Scholar 

  21. 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)

    Google Scholar 

  22. Sheard, T., Jones, S.L.P.: Template meta-programming for Haskell. ACM SIGPLAN Not. 37(12), 60–75 (2002)

    Article  Google Scholar 

  23. Swierstra, W.: Data types à la carte. J. Funct. Program. 18(4), 423–436 (2008)

    Article  MathSciNet  Google Scholar 

  24. Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. In: PEPM, pp. 203–217 (1997)

    Google Scholar 

  25. Taha, W., Sheard, T.: MetaML and multi-stage programming with explicit annotations. Theor. Comput. Sci. 248(1), 211–242 (2000). PEPM 1997

    Google Scholar 

  26. Wadler, P.: The expression problem. Mailing list (1998)

    Google Scholar 

  27. Wei, G., Bračevac, O., Tan, S., Rompf, T.: Compiling symbolic execution with staging and algebraic effects. Proc. ACM Program. Lang. 4(OOPSLA) (2020)

    Google Scholar 

  28. 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

    Chapter  Google Scholar 

  29. Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Symposium on Haskell, pp. 1–12. ACM (2014)

    Google Scholar 

  30. Yallop, J.: Staged generic programming. Proc. ACM Program. Lang. 1(ICFP), 29:1–29:29 (2017)

    Google Scholar 

Download references

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

Authors

Corresponding author

Correspondence to Birthe van den Berg .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2021 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics