Advertisement

Shallow Effect Handlers

  • Daniel Hillerström
  • Sam LindleyEmail author
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11275)

Abstract

Plotkin and Pretnar’s effect handlers offer a versatile abstraction for modular programming with user-defined effects. Traditional deep handlers are defined by folds over computation trees. In this paper we study shallow handlers, defined instead by case splits over computation trees. We show that deep and shallow handlers can simulate one another up to specific notions of administrative reduction. We present the first formal accounts of an abstract machine for shallow handlers and a Continuation Passing Style (CPS) translation for shallow handlers taking special care to avoid memory leaks. We provide implementations in the Links web programming language and empirically verify that neither implementation introduces unwarranted memory leaks.

Keywords

Effect handlers Abstract machines Continuation passing 

Notes

Acknowledgements

We would like to thank John Longley for insightful discussions about the inter-encodings of deep and shallow handlers. Daniel Hillerström was supported by EPSRC grant EP/L01503X/1 (EPSRC Centre for Doctoral Training in Pervasive Parallelism). Sam Lindley was supported by EPSRC grant EP/K034413/1 (From Data Types to Session Types—A Basis for Concurrency and Distribution).

References

  1. 1.
    Biernacki, D., Piróg, M., Polesiuk, P., Sieczkowski, F.: Handle with care: relational interpretation of algebraic effects and handlers. PACMPL 2(POPL), 8:1–8:30 (2018)Google Scholar
  2. 2.
    Cooper, E., Lindley, S., Wadler, P., Yallop, J.: Links: web programming without tiers. In: de Boer, F.S., Bonsangue, M.M., Graf, S., de Roever, W.-P. (eds.) FMCO 2006. LNCS, vol. 4709, pp. 266–296. Springer, Heidelberg (2007).  https://doi.org/10.1007/978-3-540-74792-5_12CrossRefGoogle Scholar
  3. 3.
    Danvy, O., Nielsen, L.R.: A first-order one-pass CPS transformation. Theor. Comput. Sci. 308(1–3), 239–257 (2003)MathSciNetCrossRefGoogle Scholar
  4. 4.
    Dolan, S., White, L., Sivaramakrishnan, K., Yallop, J., Madhavapeddy, A.: Effective concurrency through algebraic effects. In: OCaml Workshop (2015)Google Scholar
  5. 5.
    Felleisen, M., Friedman, D.P.: Control operators, the SECD-machine, and the \(\lambda \)-calculus. In: Formal Description of Programming Concepts III, pp. 193–217 (1987)Google Scholar
  6. 6.
    Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: PLDI, pp. 237–247. ACM (1993)Google Scholar
  7. 7.
    Fokkinga, M.M.: Tupling and mutumorphisms. Squiggolist 1(4), 81–82 (1990)Google Scholar
  8. 8.
    Goodman, N.: Uber AI Labs open sources Pyro, a deep probabilistic programming language, November 2017. https://eng.uber.com/pyro/
  9. 9.
    Hillerström, D., Lindley, S.: Liberating effects with rows and handlers. In: TyDe@ICFP, pp. 15–27. ACM (2016)Google Scholar
  10. 10.
    Hillerström, D., Lindley, S.: Shallow effect handlers (extended version) (2018). http://homepages.inf.ed.ac.uk/slindley/papers/shallow-extended.pdf
  11. 11.
    Hillerström, D., Lindley, S., Atkey, R., Sivaramakrishnan, K.C.: Continuation passing style for effect handlers. In: FSCD. LIPIcs, vol. 84, pp. 18:1–18:19 (2017)Google Scholar
  12. 12.
    Kammar, O., Lindley, S., Oury, N.: Handlers in action. In: ICFP, pp. 145–158. ACM (2013)Google Scholar
  13. 13.
    Kiselyov, O., Ishii, H.: Freer monads, more extensible effects. In: Haskell, pp. 94–105. ACM (2015)Google Scholar
  14. 14.
    Kiselyov, O., Sabry, A., Swords, C.: Extensible effects: an alternative to monad transformers. In: Haskell, pp. 59–70. ACM (2013)Google Scholar
  15. 15.
    Leijen, D.: Type directed compilation of row-typed algebraic effects. In: POPL, pp. 486–499. ACM (2017)CrossRefGoogle Scholar
  16. 16.
    Levy, P.B., Power, J., Thielecke, H.: Modelling environments in call-by-value programming languages. Inf. Comput. 185(2), 182–210 (2003)MathSciNetCrossRefGoogle Scholar
  17. 17.
    Lindley, S., McBride, C., McLaughlin, C.: Do be do be do. In: POPL, pp. 500–514. ACM (2017)Google Scholar
  18. 18.
    Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991).  https://doi.org/10.1007/3540543961_7CrossRefGoogle Scholar
  19. 19.
    Plotkin, G.D.: Call-by-name, call-by-value and the \(\lambda \)-calculus. Theor. Comput. Sci. 1(2), 125–159 (1975)MathSciNetCrossRefGoogle Scholar
  20. 20.
    Plotkin, G., Power, J.: Adequacy for algebraic effects. In: Honsell, F., Miculan, M. (eds.) FoSSaCS 2001. LNCS, vol. 2030, pp. 1–24. Springer, Heidelberg (2001).  https://doi.org/10.1007/3-540-45315-6_1CrossRefGoogle Scholar
  21. 21.
    Plotkin, G.D., Pretnar, M.: Handling algebraic effects. Log. Methods Comput. Sci. 9(4), 1–36 (2013)MathSciNetCrossRefGoogle Scholar
  22. 22.
    Reynolds, J.C.: Definitional interpreters for higher-order programming languages. High.-Order Symb. Comput. 11(4), 363–397 (1998)CrossRefGoogle Scholar
  23. 23.
    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_15CrossRefGoogle Scholar
  24. 24.
    Yallop, J.: Staged generic programming. PACMPL 1(ICFP), 29:1–29:29 (2017)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2018

Authors and Affiliations

  1. 1.The University of EdinburghEdinburghUK

Personalised recommendations