Abstract
Algebraic effects and their handlers have been steadily gaining attention as a programming language feature for composably expressing user-defined computational effects. While several prototype implementations of languages incorporating algebraic effects exist, Multicore OCaml incorporates effect handlers as the primary means of expressing concurrency in the language. In this paper, we make the observation that effect handlers can elegantly express particularly difficult programs that combine system programming and concurrency without compromising performance. Our experimental results on a highly concurrent and scalable web server demonstrate that effect handlers perform on par with highly optimised monadic concurrency libraries, while retaining the simplicity of direct-style code.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
A comprehensive list of example programs written using effect handlers in Multicore OCaml is available at https://github.com/kayceesrk/effects-examples.
- 2.
- 3.
References
Abelson, H., Dybvig, R.K., Haynes, C.T., Rozas, G.J., Adams, N., Friedman, D.P., Kohlbecker, E., Steele, G., Bartley, D.H., Halstead, R., et al.: Revised(5) report on the algorithmic language Scheme. High. Order Symbolic Comput. 11(1), 7–105 (1998)
Aeio: An asynchronous, effect-based I/O library (2017). https://github.com/kayceesrk/ocaml-aeio. Accessed 05 May 2017
Barroso, L., Marty, M., Patterson, D., Ranganathan, P.: Attack of the killer microseconds. Commun. ACM 60(4), 48–54 (2017). https://doi.org/10.1145/3015146
Bauer, A., Pretnar, M.: Programming with algebraic effects and handlers. J. Logical Algebraic Methods Program. 84(1), 108–123 (2015)
Brady, E.: Programming and reasoning with algebraic effects and dependent types. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, pp. 133–144. ACM, New York (2013). https://doi.org/10.1145/2500365.2500581
Bruggeman, C., Waddell, O., Dybvig, R.K.: Representing control in the presence of one-shot continuations. In: Fischer, C.N. (ed.) Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation (PLDI), 21–24 May 1996, pp. 99–107. ACM, Philadephia (1996)
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_12
Dolan, S., White, L., Madhavapeddy, A.: Multicore OCaml. In: OCaml Workshop (2014)
Dolan, S., White, L., Sivaramakrishnan, K.C., Yallop, J., Madhavapeddy, A.: Effective concurrency through Algebraic Effects. In: OCaml Workshop (2015)
Forster, Y., Kammar, O., Lindley, S., Pretnar, M.: On the expressive power of user-defined effects: effect handlers, monadic reflection, delimited control. Proceedings of ACM on Programming Languages, vol. 1(ICFP), pp. 13:1–13:29, August 2017. https://doi.org/10.1145/3110257
Friedman, D.P., Haynes, C.T.: Constraining control. In: Proceedings of the 12th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL 1985, pp. 245–254. ACM, New York (1985). https://doi.org/10.1145/318593.318654
Hillerström, D., Lindley, S.: Liberating effects with rows and handlers. In: Proceedings of the 1st International Workshop on Type-Driven Development, TyDe 2016, pp. 15–27. ACM, New York (2016). https://doi.org/10.1145/2976022.2976033
Hillerström, D., Lindley, S., Atkey, R., Sivaramakrishnan, K.C.: Continuation passing style for effect handlers. In: Miller, D. (ed.) 2nd International Conference on Formal Structures for Computation and Deduction (FSCD 2017). In: Leibniz International Proceedings in Informatics (LIPIcs), vol. 84, pp. 18:1–18:19. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, Dagstuhl (2017). http://drops.dagstuhl.de/opus/volltexte/2017/7739
Hillerström, D., Lindley, S., Sivaramakrishnan, K.C.: Compiling links effect handlers to the OCaml backend. In: ML Workshop (2016)
Kammar, O., Lindley, S., Oury, N.: Handlers in action. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, pp. 145–158. ACM, New York (2013). https://doi.org/10.1145/2500365.2500590
Kiselyov, O., Ishii, H.: Freer Monads, more extensible effects. In: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell, Haskell 2015, pp. 94–105. ACM, New York (2015). https://doi.org/10.1145/2804302.2804319
Kiselyov, O., Sabry, A., Swords, C.: Extensible effects: an alternative to monad transformers. In: Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Haskell 2013, pp. 59–70. ACM, New York (2013). https://doi.org/10.1145/2503778.2503791
Kiselyov, O., Sivaramakrishnan, K.C.: Eff directly in OCaml. In: ML Workshop (2016)
Leijen, D.: Structured asynchrony with algebraic effects. In: Proceedings of the 2nd ACM SIGPLAN International Workshop on Type-Driven Development, TyDe 2017, pp. 16–29. ACM, New York (2017). https://doi.org/10.1145/3122975.3122977
Leijen, D.: Type directed compilation of row-typed algebraic effects. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, pp. 486–499. ACM, New York (2017). https://doi.org/10.1145/3009837.3009872
Lindley, S., McBride, C., McLaughlin, C.: Do be do be do. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, pp. 500–514. ACM, New York (2017). https://doi.org/10.1145/3009837.3009897
Marlow, S., Jones, S.P., Moran, A., Reppy, J.: Asynchronous exceptions in Haskell. In: Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation, PLDI 2001, pp. 274–285. ACM, New York (2001). https://doi.org/10.1145/378795.378858
Marlow, S., Jones, S.P., Thaller, W.: Extending the Haskell foreign function interface with concurrency. In: Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell, Haskell 2004, pp. 22–32. ACM, New York (2004). https://doi.org/10.1145/1017472.1017479
Minsky, Y., Madhavapeddy, A., Hickey, J.: Real World OCaml - Functional Programming for the Masses. O’Reilly (2013). http://shop.oreilly.com/product/0636920024743.do#tab_04_2
Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991). https://doi.org/10.1016/0890-5401(91)90052-4
Pitman, K.M.: Condition handling in the Lisp language family. In: Romanovsky, A., Dony, C., Knudsen, J.L., Tripathi, A. (eds.) Advances in Exception Handling Techniques. LNCS, vol. 2022, pp. 39–59. Springer, Heidelberg (2001). https://doi.org/10.1007/3-540-45407-1_3
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_1
Plotkin, G.D., Pretnar, M.: Handling algebraic effects. Logical Methods Comput. Sci. 9(4) (2013). https://doi.org/10.2168/LMCS-9(4:23)2013
Pretnar, M., Saleh, A.H., Faes, A., Schrijvers, T.: Efficient compilation of algebraic effects and handlers. Technical report CW 708, KU Leuven, Belgium, October 2017
Saleh, A.H., Schrijvers, T.: Efficient algebraic effect handlers for prolog. Theory Pract. Logic Program. 16(5–6), 884–898 (2016)
Sivaramakrishnan, K.C., Harris, T., Marlow, S., Peyton Jones, S.: Composable scheduler activations for haskell. J. Funct. Program. 26, e9 (2016)
Syme, D., Petricek, T., Lomov, D.: The F# asynchronous programming model. In: Rocha, R., Launchbury, J. (eds.) PADL 2011. LNCS, vol. 6539, pp. 175–189. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-18378-2_15
Virding, R., Wikström, C., Williams, M.: Concurrent Programming in ERLANG, 2nd edn. Prentice Hall International (UK) Ltd., Hertfordshire (1996)
Vouillon, J.: Lwt: a cooperative thread library. In: Proceedings of the 2008 ACM SIGPLAN Workshop on ML, ML 2008, pp. 3–12. ACM, New York (2008). https://doi.org/10.1145/1411304.1411307
Wadler, P.: The Essence of Functional Programming. In: Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1992, pp. 1–14. ACM, New York (1992). https://doi.org/10.1145/143165.143169
Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell 2014, pp. 1–12. ACM, New York (2014). https://doi.org/10.1145/2633357.2633358
Acknowledgements
Daniel Hillerström was supported by EPSRC grant CDT in Pervasive Parallelism (EP/L01503X/1). K.C. Sivaramakrishnan was supported by a Research Fellowship from the Royal Commission for the Exhibition of 1851.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2018 Springer International Publishing AG, part of Springer Nature
About this paper
Cite this paper
Dolan, S., Eliopoulos, S., Hillerström, D., Madhavapeddy, A., Sivaramakrishnan, K.C., White, L. (2018). Concurrent System Programming with Effect Handlers. In: Wang, M., Owens, S. (eds) Trends in Functional Programming. TFP 2017. Lecture Notes in Computer Science(), vol 10788. Springer, Cham. https://doi.org/10.1007/978-3-319-89719-6_6
Download citation
DOI: https://doi.org/10.1007/978-3-319-89719-6_6
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-89718-9
Online ISBN: 978-3-319-89719-6
eBook Packages: Computer ScienceComputer Science (R0)