Skip to main content Accessibility help
×
Home

Effect handlers via generalised continuations

  • DANIEL HILLERSTRÖM (a1), SAM LINDLEY (a2) (a3) and ROBERT ATKEY (a4)

Abstract

Plotkin and Pretnar’s effect handlers offer a versatile abstraction for modular programming with user-defined effects. This paper focuses on foundations for implementing effect handlers, for the three different kinds of effect handlers that have been proposed in the literature: deep, shallow, and parameterised. Traditional deep handlers are defined by folds over computation trees and are the original construct proposed by Plotkin and Pretnar. Shallow handlers are defined by case splits (rather than folds) over computation trees. Parameterised handlers are deep handlers extended with a state value that is threaded through the folds over computation trees. We formulate the extensions both directly and via encodings in terms of deep handlers and illustrate how the direct implementations avoid the generation of unnecessary closures. We give two distinct foundational implementations of all the kinds of handlers we consider: a continuation-passing style (CPS) transformation and a CEK-style abstract machine. In both cases, the key ingredient is a generalisation of the notion of continuation to accommodate stacks of effect handlers. We obtain our CPS translation through a series of refinements as follows. We begin with a first-order CPS translation into untyped lambda calculus which manages a stack of continuations and handlers as a curried sequence of arguments. We then refine the initial CPS translation by uncurrying it to yield a properly tail-recursive translation and then moving towards more and more intensional representations of continuations in order to support different kinds of effect handlers. Finally, we make the translation higher order in order to contract administrative redexes at translation time. Our abstract machine design then uses the same generalised continuation representation as the CPS translation. We have implemented both the abstract machine and the CPS transformation (plus extensions) as backends for the Links web programming language.

    • Send article to Kindle

      To send this article to your Kindle, first ensure no-reply@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about sending to your Kindle. Find out more about sending to your Kindle.

      Note you can select to send to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be sent to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

      Find out more about the Kindle Personal Document Service.

      Effect handlers via generalised continuations
      Available formats
      ×

      Send article to Dropbox

      To send this article to your Dropbox account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your <service> account. Find out more about sending content to Dropbox.

      Effect handlers via generalised continuations
      Available formats
      ×

      Send article to Google Drive

      To send this article to your Google Drive account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your <service> account. Find out more about sending content to Google Drive.

      Effect handlers via generalised continuations
      Available formats
      ×

Copyright

References

Hide All
Appel, A. W. (1992) Compiling with Continuations. Cambridge University.
Bauer, A. & Pretnar, M. (2015) Programming with algebraic effects and handlers. J. Log. Alg. Meth. Program. 84(1), 108123.
Berdine, J., O’Hearn, P. W., Reddy, U. S. & Thielecke, H. (2002) Linear continuation-passing. Higher-Order Symb. Comput. 15(2–3), 181208.10.1023/A:1020891112409
Biernacki, D., Piróg, M., Polesiuk, P. & Sieczkowski, F. (2018) Handle with care: Relational interpretation of algebraic effects and handlers. PACMPL 2(POPL), 8:18:30.
Biernacki, D., Piróg, M., Polesiuk, P. & Sieczkowski, F. (2019) Abstracting algebraic effects. PACMPL 3(POPL), 6:16:28.
Bingham, E., Chen, J. P., Jankowiak, M., Obermeyer, F., Pradhan, N., Karaletsos, T., Singh, R., Szerlip, P., Horsfall, P. & Goodman, N. D. (2018) Pyro: Deep universal probabilistic programming. J. Mach. Learn. Res, 28:1–28:6.
Bouton, C. L. (1901) Nim, a game with a complete mathematical theory. Ann. Math. 3(1/4), 3539.10.2307/1967631
Brachthäuser, J. I. & Schuster, P. (2017) Effekt: Extensible algebraic effects in scala (short paper). In SCALA@SPLASH. ACM, pp. 6772.10.1145/3136000.3136007
Brachthäuser, J. I., Schuster, P. & Ostermann, K. (2018) Effect handlers for the masses. PACMPL 2(OOPSLA), 111:1111:27.
Brachthäuser, J. I., Schuster, P. & Ostermann, K. (to appear) Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala. J. Funct. Program. 30.
Bruggeman, C., Waddell, O. & Dybvig, R. K. (1996) Representing control in the presence of one-shot continuations. In Proceedings of the ACM SIGPLAN’96 Conference on Programming Language Design and Implementation (PLDI), Philadephia, Pennsylvania, May 21–24, 1996, Fischer, C. N. (ed). ACM, pp. 99107.10.1145/231379.231395
Convent, L., Lindley, S., McBride, C. & McLaughlin, C. (to appear) Doo bee doo bee doo. J. Funct. Program. 30.
Cooper, E., Lindley, S., Wadler, P. & Yallop, J. (2006) Links: Web programming without tiers. In FMCO. LNCS, vol. 4709. Springer, pp. 266296.
Danvy, O. & Filinski, A. (1990) Abstracting control. In LISP and Functional Programming, pp. 151160.10.1145/91556.91622
Danvy, O. & Filinski, A. (1992) Representing control: A study of the CPS transformation. Math. Struct. Comput. Sci. 2(4), 361391.10.1017/S0960129500001535
Danvy, O. & Nielsen, L. R. (2003) A first-order one-pass CPS transformation. Theor. Comput. Sci. 308(1–3), 239257.10.1016/S0304-3975(02)00733-8
Dolan, S., Eliopoulos, S., Hillerström, D., Madhavapeddy, A., Sivaramakrishnan, K. C. & White, L. (2017) Concurrent system programming with effect handlers. In TFP. Lecture Notes in Computer Science, vol. 10788. Springer, pp. 98117.
Dolan, S., White, L. & Madhavapeddy, A. (2014) Multicore OCaml. In OCaml Workshop.
Dolan, S., White, L., Sivaramakrishnan, K. C., Yallop, J. & Madhavapeddy, A. (2015) Effective concurrency through algebraic effects. In OCaml Workshop.
Dybvig, R. K., Peyton Jones, S. L. & Sabry, A. (2007) A monadic framework for delimited continuations. J. Funct. Program. 17(6), 687730.
Felleisen, M. & Friedman, D. P. (1987) Control operators, the SECD-machine, and the λ-calculus. In Formal Description of Programming Concepts III, Wirsing, Martin (ed). Elsevier, pp. 193217.
Flanagan, C., Sabry, A., Duba, B. F. & Felleisen, M. (1993) The essence of compiling with continuations. In PLDI. ACM, pp. 237247.10.1145/155090.155113
Fokkinga, M. M. (1990) Tupling and mutumorphisms. Squiggolist 1(4), 8182.
Forster, Y., Kammar, O., Lindley, S. & Pretnar, M. (2017) On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control. PACMPL 1(ICFP), e15.
Forster, Y., Kammar, O., Lindley, S. & Pretnar, M. (2019) On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control. J. Funct. Program. 29, e15.10.1017/S0956796819000121
Hillerström, D. (2015) Handlers for Algebraic Effects in Links. MSc thesis, The University of Edinburgh, Scotland.
Hillerström, D. (2016) Compilation of Effect Handlers and their Applications in Concurrency. MSc(R) thesis, The University of Edinburgh, Scotland.
Hillerström, D. & Lindley, S. (2016) Liberating effects with rows and handlers. In TyDe@ICFP. ACM, pp. 1527.10.1145/2976022.2976033
Hillerström, D. & Lindley, S. (2018) Shallow effect handlers. In APLAS, vol. 11275. Springer International Publishing, pp. 415433.
Hillerström, D., Lindley, S., Atkey, R. & Sivaramakrishnan, K. C. (2017) Continuation passing style for effect handlers. In FSCD. LIPIcs, vol. 84. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, pp. 18:1–18:19.
Hillerström, D., Lindley, S. & Sivaramakrishnan, K. C. (2016) Compiling Links effect handlers to the OCaml backend. In ML Workshop.
Huet, G. P. (1997) The zipper. J. Funct. Program. 7(5), 549554.10.1017/S0956796897002864
James, R. P. & Sabry, A. (2011) Yield: Mainstream delimited continuations. In TPDC.
Kammar, O., Lindley, S. & Oury, N. (2013) Handlers in action. In ICFP. ACM, pp. 145158.10.1145/2500365.2500590
Kennedy, A. (2007) Compiling with continuations, continued. In ICFP. ACM, pp. 177190.10.1145/1291151.1291179
Kiselyov, O. (2012) Delimited control in OCaml, abstractly and concretely. Theor. Comput. Sci. 435, 5676.10.1016/j.tcs.2012.02.025
Kiselyov, O. & Sivaramakrishnan, K. C. (2016) Eff directly in OCaml. In ML Workshop.
Kranz, D., Kelsey, R., Rees, J., Hudak, P., Philbin, J. & Adams, N. (1986) ORBIT: An optimizing compiler for Scheme. 21(7), 219233. Proceedings of the SIGPLAN’86 Symposium on Compiler Construction.10.1145/13310.13333
Leijen, D. (2014) Koka: Programming with row polymorphic effect types. In MSFP. EPTCS, vol. 153, pp. 100126.10.4204/EPTCS.153.8
Leijen, D. (2017a) Implementing algebraic effects in C - “monads for free in C”. In APLAS. Lecture Notes in Computer Science, vol. 10695. Springer, pp. 339363.
Leijen, D. (2017b) Structured asynchrony with algebraic effects. In TyDe@ICFP. ACM, pp. 1629.10.1145/3122975.3122977
Leijen, D. (2017c) Type directed compilation of row-typed algebraic effects. In POPL. ACM, pp. 486499.10.1145/3093333.3009872
Levy, P. B., Power, J. & Thielecke, H. (2003) Modelling environments in call-by-value programming languages. Inf. Comput. 185(2), 182210.10.1016/S0890-5401(03)00088-9
Lindley, S., McBride, C. & McLaughlin, C. (2017) Do be do be do. In POPL. ACM, pp. 500514.10.1145/3009837.3009897
Materzok, M. & Biernacki, D. (2012) A dynamic interpretation of the CPS hierarchy. In APLAS. LNCS, vol. 7705. Springer, pp. 296311.
McBride, C. (2016) Shonky. https://github.com/pigworker/shonky.
Meijer, E., Fokkinga, M. M. & Paterson, R. (1991) Functional programming with bananas, lenses, envelopes and barbed wire. In FPCA. Lecture Notes in Computer Science, vol. 523. Springer, pp. 124144.
Piróg, M., Polesiuk, P. & Sieczkowski, F. (2019) Typed equivalence of effect handlers and delimited control. In FSCD. LIPIcs, vol. 131. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, pp. 30:1–30:16.
Plotkin, G. D. (1975) Call-by-name, call-by-value and the lambda-calculus. Theor. Comput. Sci. 1(2), 125159.10.1016/0304-3975(75)90017-1
Plotkin, G. D. & Power, J. (2001) Adequacy for algebraic effects. In FoSSaCS. LNCS, vol. 2030. Springer, pp. 124.
Plotkin, G. D. & Pretnar, M. (2013) Handling algebraic effects. Log. Methods Comput. Sci. 9(4).10.2168/LMCS-9(4:23)2013
Pretnar, M. (2015) An introduction to algebraic effects and handlers. Electr. Notes Theor. Comput. Sci. 319, 1935. Invited tutorial paper.10.1016/j.entcs.2015.12.003
Remy, D. (1993). Syntactic Theories and the Algebra of Record Terms. Technical report RR-1869. INRIA.
Shan, C.-c. (2007) A static simulation of dynamic delimited control. Higher-Order Symb. Comput 20(4), 371401.10.1007/s10990-007-9010-4
Steele, G. (1978) RABBIT: A Compiler for SCHEME. Technical report. AITR-474. INRIA.
Wadler, P. (1995) Monads for functional programming. In Advanced Functional Programming. Lecture Notes in Computer Science, vol. 925. Springer, pp. 2452.
Wu, N. & Schrijvers, T. (2015) Fusion for free - efficient algebraic effect handlers. In MPC. Lecture Notes in Computer Science, vol. 9129. Springer, pp. 302322.
Wu, N., Schrijvers, T. & Hinze, R. (2014) Effect handlers in scope. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Gothenburg, Sweden, September 4–5, 2014, Swierstra, W. (ed). ACM, pp. 112.10.1145/2633357.2633358
Yallop, J. (2017) Staged generic programming. PACMPL 1(ICFP), 29:129:29.

Effect handlers via generalised continuations

  • DANIEL HILLERSTRÖM (a1), SAM LINDLEY (a2) (a3) and ROBERT ATKEY (a4)

Metrics

Altmetric attention score

Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

Effect handlers via generalised continuations

  • DANIEL HILLERSTRÖM (a1), SAM LINDLEY (a2) (a3) and ROBERT ATKEY (a4)
Submit a response

Discussions

We encountered an error trying to retrieve Discussions for this article. Please try again or contact Customer Services

×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *