Skip to main content Accessibility help
×
Home
Hostname: page-component-559fc8cf4f-xbbwl Total loading time: 0.78 Render date: 2021-03-07T07:11:07.167Z Has data issue: true Feature Flags: { "shouldUseShareProductTool": true, "shouldUseHypothesis": true, "isUnsiloEnabled": true, "metricsAbstractViews": false, "figures": false, "newCiteModal": false, "newCitedByModal": true }

Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala

Published online by Cambridge University Press:  31 March 2020

JONATHAN IMMANUEL BRACHTHÄUSER
Affiliation:
University of Tübingen, Tübingen, Germany (e-mails: jonathan.brachthaeuser@uni-tuebingen.de, philipp.schuster@uni-tuebingen.de, klaus.ostermann@uni-tuebingen.de)
PHILIPP SCHUSTER
Affiliation:
University of Tübingen, Tübingen, Germany (e-mails: jonathan.brachthaeuser@uni-tuebingen.de, philipp.schuster@uni-tuebingen.de, klaus.ostermann@uni-tuebingen.de)
KLAUS OSTERMANN
Affiliation:
University of Tübingen, Tübingen, Germany (e-mails: jonathan.brachthaeuser@uni-tuebingen.de, philipp.schuster@uni-tuebingen.de, klaus.ostermann@uni-tuebingen.de)
Rights & Permissions[Opens in a new window]

Abstract

Effect handlers are a promising way to structure effectful programs in a modular way. We present the Scala library Effekt, which is centered around capability passing and implemented in terms of a monad for multi-prompt delimited continuations. Effekt is the first library implementation of effect handlers that supports effect safety and effect polymorphism without resorting to type-level programming. We describe a novel way of achieving effect safety using intersection types and path-dependent types. The effect system of our library design fits well into the programming paradigm of capability passing and is inspired by the effect system of Zhang & Myers (2019, Proc. ACM Program. Lang.3(POPL), 5:1-5:29). Capabilities carry an abstract type member, which represents an individual effect type and reflects the use of the capability on the type level. We represent effect rows as the contravariant intersection of effect types. Handlers introduce capabilities and remove components of the intersection type. Reusing the existing type system of Scala, we get effect subtyping and effect polymorphism for free.

Type
Research Article
Creative Commons
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited.
Copyright
© The Author(s) 2020. Published by Cambridge University Press

References

Amin, N. & Tate, R. (2016) Java and Scala’s type systems are unsound: The existential crisis of null pointers. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. New York, NY, USA: ACM, pp. 838848.Google Scholar
Bauer, A. & Pretnar, M. (2015) Programming with algebraic effects and handlers. J. Log. Alg. Methods Program. 84(1), 108123.Google Scholar
Biernacki, D., Piróg, M., Polesiuk, P., & Sieczkowski, F. (2017) Handle with care: Relational interpretation of algebraic effects and handlers. Proc. ACM Program. Lang. 2(POPL), 8:1–8:30.Google Scholar
Biernacki, D., Piróg, M., Polesiuk, P. & Sieczkowski, F. (2019) Abstracting algebraic effects. Proc. ACM Program. Lang. 3(POPL), 6:1–6:28.CrossRefGoogle Scholar
Brachthäuser, J. I. & Schuster, P. (2017) Effekt: Extensible algebraic effects in Scala (short paper). In Proceedings of the International Symposium on Scala. New York, NY, USA: ACM.Google Scholar
Brachthäuser, J. I., Schuster, P. & Ostermann, K. (2018) Effect handlers for the masses. Proc. ACM Program. Lang. 2(OOPSLA), 111:1–111:27.CrossRefGoogle Scholar
Carette, J., Kiselyov, O. & Shan, C.-C. (2007) Finally tagless, partially evaluated. In Proceedings of the Asian Symposium on Programming Languages and Systems. LNCS, vol. 4807. Berlin, Heidelberg: Springer, pp. 222238.Google Scholar
Convent, L., Lindley, S., McBride, C. & McLaughlin, C. (2019) Doo Bee Doo Bee Doo. Technical report. The University of Edinburgh.Google Scholar
Danvy, O. & Filinski, A. (1992) Representing control: A study of the CPS transformation. Math. Struct. Comput. Sci. 2(4), 361391.CrossRefGoogle Scholar
Danvy, O. & Filinski, A. (1989) A functional abstraction of typed contexts. Diku rapport 89/12, diku, University of Copenhagen.Google Scholar
Danvy, O. & Filinski, A. (1990) Abstracting control. In Proceedings of the Conference on LISP and Functional Programming. New York, NY, USA: ACM, pp. 151160.Google Scholar
Dolan, S., Eliopoulos, S., Hillerström, D., Madhavapeddy, A., Sivaramakrishnan, K. C. & White, L. (2017) Concurrent system programming with effect handlers. In Proceedings of the Symposium on Trends in Functional Programming. LNCS, vol. 10788. Springer.CrossRefGoogle Scholar
Dolan, S., White, L. & Madhavapeddy, A. (2014) Multicore OCaml. In OCaml Workshop.Google Scholar
Dolan, S., White, L., Sivaramakrishnan, K. C., Yallop, J. & Madhavapeddy, A. (2015) Effective concurrency through algebraic effects. In OCaml Workshop.Google Scholar
Dybvig, R. K., Peyton, J., Simon, L. & Sabry, A. (2007) A monadic framework for delimited continuations. J. Funct. Program. 17(6), 687730.Google Scholar
Felleisen, M. (1988) The theory and practice of first-class prompts. In Proceedings of the Symposium on Principles of Programming Languages. New York, NY, USA: ACM, pp. 180190.Google Scholar
Forster, Y., Kammar, O., Lindley, S. & Pretnar, M. (2017) On the expressive power of userdefined effects: Effect handlers, monadic reflection, delimited control. Proc. ACM Program. Lang. 1(ICFP), 13:113:29.CrossRefGoogle Scholar
Friedman, D. P., Haynes, C. T. & Kohlbecker, E. (1984) Programming with continuations. In Program Transformation and Programming Environments, Pepper, P. (ed), Berlin, Heidelberg: Springer-Verlag.Google Scholar
Gaster, B. R. & Jones, M. P. (1996) A Polymorphic Type System for Extensible Records and Variants. Technical report NOTTCS-TR-96-3.Google Scholar
Gunter, C. A., Rémy, D. & Riecke, J. G. (1995) A generalization of exceptions and control in ML-like languages. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture. New York, NY, USA: ACM, pp. 1223.Google Scholar
Haller, P. & Loiko, A. (2016) LaCasa: Lightweight affinity and object capabilities in Scala. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. New York, NY, USA: ACM, pp. 272291.Google Scholar
Hieb, R. & Dybvig, R. K. (1990) Continuations and concurrency. In Proceedings of the Second ACM SIGPLAN Symposium on Principles & Practice of Parallel Programming. PPOPP’90. New York, NY, USA: ACM, pp. 128136.Google Scholar
Hieb, R., Dybvig, R. K. & Anderson, III, C. W. (1994) Subcontinuations. Lisp Symb. Comput. 7(1), 83110.CrossRefGoogle Scholar
Hillerström, D. & Lindley, S. (2016) Liberating effects with rows and handlers. In Proceedings of the Workshop on Type-Driven Development. New York, NY, USA: ACM.Google Scholar
Hillerström, D., Lindley, S., Atkey, B. & Sivaramakrishnan, K. C. (2017) Continuation passing style for effect handlers. In Formal Structures for Computation and Deduction, LIPIcs, vol. 84. Schloss Dagstuhl–Leibniz-Zentrum für Informatik.Google Scholar
Hudak, P. (1998) Modular domain specific languages and tools. In Proceedings of the Conference on Software Reuse. IEEE Computer Society, pp. 134142.CrossRefGoogle Scholar
Inostroza, P. & van der Storm, T. (2018). JEff: Objects for effect. In Proceedings of the 2018 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software. Onward! 2018. New York, NY, USA: ACM.Google Scholar
Johnson, G. F. & Duggan, D. (1988). Stores and partial continuations as first-class objects in a language and its environment. In Proceedings of the Symposium on Principles of Programming Languages. New York, NY, USA: ACM, pp. 158168.Google Scholar
Kammar, O., Lindley, S. & Oury, N. (2013) Handlers in action. In Proceedings of the International Conference on Functional Programming. New York, NY, USA: ACM, pp. 145158.Google Scholar
Kiselyov, O. & Ishii, H. (2015) Freer monads, more extensible effects. In Proceedings of the Haskell Symposium. New York, NY, USA: ACM, pp. 94105.Google Scholar
Kiselyov, O. & Shan, C.-c. (2008) Lightweight monadic regions. In Proceedings of the Haskell Symposium. Haskell’08. New York, NY, USA: ACM.Google Scholar
Kiselyov, O. & Sivaramakrishnan, K. C. (2016). Eff directly in OCaml. In ML Workshop.Google Scholar
Kiselyov, O. & Sivaramakrishnan, K. C. (2018) Eff directly in OCaml. In Proceedings of the ML Family Workshop/OCaml Users and Developers Workshops, Asai, K. & Shinwell, M. (eds). Electronic Proceedings in Theoretical Computer Science, vol. 285. Open Publishing Association, pp. 2358.CrossRefGoogle Scholar
Kiselyov, O., Sabry, A. & Swords, C. (2013) Extensible effects: An alternative to monad transformers. In Proceedings of the Haskell Symposium. New York, NY, USA: ACM, pp. 5970.Google Scholar
Kiselyov, O., Shan, C.-c. & Sabry, A. (2006) Delimited dynamic binding. In Proceedings of the International Conference on Functional Programming. New York, NY, USA: ACM, pp. 2637.Google Scholar
Kobori, I., Kameyama, Y. & Kiselyov, O. (2016) Answer-type modification without tears: Promptpassing style translation for typed delimited-control operators. arxiv preprint arxiv:1606.06379.CrossRefGoogle Scholar
Launchbury, J. & Sabry, A. (1997) Monadic state: Axiomatization and type safety. In Proceedings of the International Conference on Functional Programming. ICFP’97. New York, NY, USA: ACM, pp. 227238.Google Scholar
Leijen, D. (2014) Koka: Programming with row polymorphic effect types. In Proceedings of the Workshop on Mathematically Structured Functional Programming.CrossRefGoogle Scholar
Leijen, D. (2016) Algebraic Effects for Functional Programming. Technical report MSR-TR-2016-29. Microsoft Research technical report.Google Scholar
Leijen, D. (2017a) Implementing algebraic effects in C. In Proceedings of the Asian Symposium on Programming Languages and Systems. Cham, Switzerland: Springer International Publishing, pp. 339363.CrossRefGoogle Scholar
Leijen, D. (2017b). Structured asynchrony with algebraic effects. In Proceedings of the Workshop on Type-Driven Development. New York, NY, USA: ACM, pp. 1629.Google Scholar
Leijen, D. (2017c). Type directed compilation of row-typed algebraic effects. In Proceedings of the Symposium on Principles of Programming Languages. New York, NY, USA: ACM, pp. 486499.Google Scholar
Leijen, D. (2018). First class dynamic effect handlers: Or, polymorphic heaps with dynamic effect handlers. In Proceedings of the Workshop on Type-Driven Development. New York, NY, USA: ACM, pp. 5164.Google Scholar
Liang, S., Hudak, P. & Jones, M. (1995)Monad transformers and modular interpreters. In Proceedings of the Symposium on Principles of Programming Languages. New York, NY, USA: ACM, pp. 333343.Google Scholar
Lindley, S. (2018) Encapsulating effects. Dagstuhl Reports, 8(4).Google Scholar
Lindley, S., McBride, C. & McLaughlin, C. (2017) Do be do be do. In Proceedings of the Symposium on Principles of Programming Languages. New York, NY, USA: ACM, pp. 500514.Google Scholar
Liu, F. (2016) A Study of Capability-Based Effect Systems. M.Phil. thesis, École Polytechnique Fédérale de Lausanne, Switzerland.Google Scholar
Materzok, M. & Biernacki, D. (2011) Subtyping delimited continuations. In Proceedings of the International Conference on Functional Programming. New York, NY, USA: ACM, pp. 8193.Google Scholar
Moggi, E. & Sabry, A. (2001) Monadic encapsulation of effects: A revised approach (extended version). J. Funct. Program. 11(6), 591627.CrossRefGoogle Scholar
Odersky, M., Blanvillain, O., Liu, F., Biboudis, A., Miller, H. & Stucki, S. (2017) Simplicitly: Foundations and applications of implicit function types. Proc. ACM Program. Lang. 2(POPL), 42:142:29.Google Scholar
Odersky, M. & Zenger, M. (2005a) Independently extensible solutions to the expression problem. In Proceedings of the Workshop on Foundations of Object-Oriented Languages.Google Scholar
Odersky, M. & Zenger, M. (2005b) Scalable component abstractions. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. New York, NY, USA: ACM, pp. 4157.Google Scholar
Oliveira, B. C. d. S., & Cook, W. R. (2012) Extensibility for the masses: Practical extensibility with object algebras. In Proceedings of the European Conference on Object-Oriented Programming. LNCS, vol. 7313. Springer, pp. 227.Google Scholar
Osvald, L., Essertel, G., Wu, X., Alayón, L. I. G.& Rompf, T. (2016) Gentrification gone too far? affordable 2nd-class values for fun and (co-) effect. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. New York, NY, USA: ACM, pp. 234251.Google Scholar
Parreaux, L., Voizard, A., Shaikhha, A. & Koch, C. E. (2017). Unifying analytic and statically-typed quasiquotes. Proc. ACM Program. Lang. 2(POPL), 13:113:33.Google Scholar
Piróg, M., Polesiuk, P. & Sieczkowski, F. (2019) Typed equivalence of effect handlers and delimited control. In Formal Structures for Computation and Deduction. LIPIcs. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, pp. 30:1–30:16.Google Scholar
Plotkin, G. & Power, J. (2003) Algebraic operations and generic effects. Appl. Categor. Struct. 11(1), 6994.CrossRefGoogle Scholar
Plotkin, G. & Pretnar, M. (2009) Handlers of algebraic effects. In European Symposium on Programming. Springer-Verlag, pp. 8094.Google Scholar
Plotkin, G. D. & Pretnar, M. (2013) Handling algebraic effects. Log. Methods Comput. Sci. 9(4), 136.CrossRefGoogle Scholar
Rapoport, M. & Lhoták, O. (2019). A path to DOT: formalizing fully-path-dependent types. Corr, abs/1904.07298.CrossRefGoogle Scholar
Sitaram, D. & Felleisen, M. (1990) Control delimiters and their hierarchies. Lisp Symb. Comput. 3(1), 6799.CrossRefGoogle Scholar
Wadler, P. (1998). The expression problem. Note to Java Genericity mailing list.Google Scholar
Wright, A. K. & Felleisen, M. (1994) A syntactic approach to type soundness. Inf. Comput. 115(1), 3894.CrossRefGoogle Scholar
Wu, N., Schrijvers, T. & Hinze, R. (2014) Effect handlers in scope. In Proceedings of the Haskell Symposium. Haskell’14. New York, NY, USA: ACM, pp. 112.Google Scholar
Zhang, Y. & Myers, A. C. (2019) Abstraction-safe effect handlers via tunneling. Proc. ACM Program. Lang. 3(POPL), 5:15:29.Google Scholar
Zhang, Y., Salvaneschi, G., Beightol, Q., Liskov, B. & Myers, A. C. (2016) Accepting blame for safe tunneled exceptions. Proceedings of the Conference on Programming Language Design and Implementation. New York, NY, USA: ACM, pp. 281295.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.

Altmetric attention score

Full text views

Full text views reflects PDF downloads, PDFs sent to Google Drive, Dropbox and Kindle and HTML full text views.

Total number of HTML views: 0
Total number of PDF views: 1099 *
View data table for this chart

* Views captured on Cambridge Core between 31st March 2020 - 7th March 2021. This data will be updated every 24 hours.

Access
Open access

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.

Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala
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.

Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala
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.

Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala
Available formats
×
×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *