A Direct-Style Effect Notation for Sequential and Parallel Programs

Authors David Richter , Timon Böhler , Pascal Weisenburger , Mira Mezini

Thumbnail PDF


  • Filesize: 0.84 MB
  • 22 pages

Document Identifiers

Author Details

David Richter
  • Technische Universität Damstadt, Germany
Timon Böhler
  • Technische Universität Damstadt, Germany
Pascal Weisenburger
  • Universität St. Gallen, Switzerland
Mira Mezini
  • Technische Universität Damstadt, Germany
  • hessian.AI, Darmstadt, Germany

Cite AsGet BibTex

David Richter, Timon Böhler, Pascal Weisenburger, and Mira Mezini. A Direct-Style Effect Notation for Sequential and Parallel Programs. In 37th European Conference on Object-Oriented Programming (ECOOP 2023). Leibniz International Proceedings in Informatics (LIPIcs), Volume 263, pp. 25:1-25:22, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2023)


Modeling sequential and parallel composition of effectful computations has been investigated in a variety of languages for a long time. In particular, the popular do-notation provides a lightweight effect embedding for any instance of a monad. Idiom bracket notation, on the other hand, provides an embedding for applicatives. First, while monads force effects to be executed sequentially, ignoring potential for parallelism, applicatives do not support sequential effects. Composing sequential with parallel effects remains an open problem. This is even more of an issue as real programs consist of a combination of both sequential and parallel segments. Second, common notations do not support invoking effects in direct-style, instead forcing a rigid structure upon the code. In this paper, we propose a mixed applicative/monadic notation that retains parallelism where possible, but allows sequentiality where necessary. We leverage a direct-style notation where sequentiality or parallelism is derived from the structure of the code. We provide a mechanisation of our effectful language in Coq and prove that our compilation approach retains the parallelism of the source program.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Domain specific languages
  • Software and its engineering → Concurrent programming structures
  • Software and its engineering → Parallel programming languages
  • do-notation
  • parallelism
  • concurrency
  • effects


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. Relative monads formalised. Journal of Formalized Reasoning, 7(1):1-43, 2014. URL: https://doi.org/10.6092/issn.1972-5787/4389.
  2. Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. Monads need not be endofunctors. Logical Methods in Computer Science, 11(1), 2015. URL: https://doi.org/10.2168/LMCS-11(1:3)2015.
  3. Nick Benton, Chung-Kil Hur, Andrew Kennedy, and Conor McBride. Strongly typed term representations in Coq. J. Autom. Reason., 49(2):141-159, 2012. URL: https://doi.org/10.1007/s10817-011-9219-0.
  4. Gavin M. Bierman, Erik Meijer, and Mads Torgersen. Lost in translation: formalizing proposed extensions to C#. In Richard P. Gabriel, David F. Bacon, Cristina Videira Lopes, and Guy L. Steele Jr., editors, Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2007, October 21-25, 2007, Montreal, Quebec, Canada, pages 479-498. ACM, 2007. URL: https://doi.org/10.1145/1297027.1297063.
  5. Gavin M. Bierman, Claudio V. Russo, Geoffrey Mainland, Erik Meijer, and Mads Torgersen. Pause 'n' play: Formalizing asynchronous C#. In James Noble, editor, ECOOP 2012 - Object-Oriented Programming - 26th European Conference, Beijing, China, June 11-16, 2012. Proceedings, volume 7313 of Lecture Notes in Computer Science, pages 233-257. Springer, 2012. URL: https://doi.org/10.1007/978-3-642-31057-7_12.
  6. Edwin C. Brady. Resource-dependent algebraic effects. In Jurriaan Hage and Jay McCarthy, editors, Trends in Functional Programming - 15th International Symposium, TFP 2014, Soesterberg, The Netherlands, May 26-28, 2014. Revised Selected Papers, volume 8843 of Lecture Notes in Computer Science, pages 18-33. Springer, 2014. URL: https://doi.org/10.1007/978-3-319-14675-1_2.
  7. Flavio W. Brasil and Sameer Brenn. Monadless - syntactic sugar for monad composition in Scala. URL: https://github.com/monadless/monadless.
  8. Adam Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In James Hook and Peter Thiemann, editors, Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008, pages 143-156. ACM, 2008. URL: https://doi.org/10.1145/1411204.1411226.
  9. Coq 8.16 reference manual. URL: https://coq.github.io/doc/v8.16/refman/.
  10. Tom Crockett. Effectful: A syntax for typeful effectful computations in Scala. https://github.com/pelotom/effectful#effects-within-conditionals. Accessed 20-11-2020.
  11. Nils Anders Danielsson. A formalisation of a dependently typed language as an inductive-recursive family. In Thorsten Altenkirch and Conor McBride, editors, Types for Proofs and Programs, International Workshop, TYPES 2006, Nottingham, UK, April 18-21, 2006, Revised Selected Papers, volume 4502 of Lecture Notes in Computer Science, pages 93-109. Springer, 2006. URL: https://doi.org/10.1007/978-3-540-74464-1_7.
  12. Olivier Danvy and Lasse R. Nielsen. A first-order one-pass CPS transformation. Theor. Comput. Sci., 308(1-3):239-257, 2003. URL: https://doi.org/10.1016/S0304-3975(02)00733-8.
  13. Levent Erkök and John Launchbury. A recursive do for Haskell. In Manuel M. T. Chakravarty, editor, Proceedings of the 2002 ACM SIGPLAN Workshop on Haskell, Haskell 2002, Pittsburgh, Pennsylvania, USA, October 3, 2002, pages 29-37. ACM, 2002. URL: https://doi.org/10.1145/581690.581693.
  14. Andrzej Filinski. Representing monads. In Hans-Juergen Boehm, Bernard Lang, and Daniel M. Yellin, editors, Conference Record of POPL'94: 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Portland, Oregon, USA, January 17-21, 1994, pages 446-457. ACM Press, 1994. URL: https://doi.org/10.1145/174675.178047.
  15. Michael J. Fischer. Lambda calculus schemata. In Proceedings of ACM Conference on Proving Assertions About Programs, Las Cruces, New Mexico, USA, January 6-7, 1972, pages 104-109. ACM, 1972. URL: https://doi.org/10.1145/800235.807077.
  16. Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control. Journal of Functional Programming, 29:e15, 2019. URL: https://doi.org/10.1017/S0956796819000121.
  17. Robert Harper and Christopher A. Stone. A type-theoretic interpretation of Standard ML. In Gordon D. Plotkin, Colin Stirling, and Mads Tofte, editors, Proof, Language, and Interaction, Essays in Honour of Robin Milner, pages 341-388. The MIT Press, 2000. Google Scholar
  18. Haskell Proposals. Delimited continuation primops. URL: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0313-delimited-continuation-primops.rst.
  19. Martin Hofmann. Semantical analysis of higher-order abstract syntax. In 14th Annual IEEE Symposium on Logic in Computer Science, Trento, Italy, July 2-5, 1999, pages 204-213. IEEE Computer Society, 1999. URL: https://doi.org/10.1109/LICS.1999.782616.
  20. John Hughes. Generalising monads to arrows. Science of Computer Programming, 37(1-3):67-111, 2000. URL: https://doi.org/10.1016/S0167-6423(99)00023-4.
  21. The Idris Tutorial. Interfaces. Monads and do-notation. !-notation. http://docs.idris-lang.org/en/latest/tutorial/interfaces.html#notation. Accessed 14-11-2020.
  22. Hiroaki Inoue, Tomoyuki Aotani, and Atsushi Igarashi. Contextworkflow: A monadic DSL for compensable and interruptible executions. In Todd D. Millstein, editor, 32nd European Conference on Object-Oriented Programming, ECOOP 2018, July 16-21, 2018, Amsterdam, The Netherlands, volume 109 of LIPIcs, pages 2:1-2:33. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2018. URL: https://doi.org/10.4230/LIPIcs.ECOOP.2018.2.
  23. Jerzy Karczmarczuk. Functional differentiation of computer programs. In Matthias Felleisen, Paul Hudak, and Christian Queinnec, editors, Proceedings of the third ACM SIGPLAN International Conference on Functional Programming (ICFP '98), Baltimore, Maryland, USA, September 27-29, 1998, pages 195-203. ACM, 1998. URL: https://doi.org/10.1145/289423.289442.
  24. Github. Kind2. A next-gen functional language. https://github.com/Kindelia/Kind2. Accessed 29-11-2022.
  25. Lean Manual. The do notation. Nested actions. https://leanprover.github.io/lean4/doc/do.html#nested-actions. Accessed 29-11-2022.
  26. Sam Lindley, Philip Wadler, and Jeremy Yallop. Idioms are oblivious, arrows are meticulous, monads are promiscuous. Electronic Notes in Theoretical Computer Science, 229(5):97-117, 2011. URL: https://doi.org/10.1016/j.entcs.2011.02.018.
  27. Simon Marlow, Louis Brandy, Jonathan Coens, and Jon Purdy. There is no fork: an abstraction for efficient, concurrent, and concise data access. In Johan Jeuring and Manuel M. T. Chakravarty, editors, Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014, pages 325-337. ACM, 2014. URL: https://doi.org/10.1145/2628136.2628144.
  28. Simon Marlow, Simon Peyton Jones, Edward Kmett, and Andrey Mokhov. Desugaring Haskell’s do-notation into applicative operations. In Geoffrey Mainland, editor, Proceedings of the 9th International Symposium on Haskell, Haskell 2016, Nara, Japan, September 22-23, 2016, pages 92-104. ACM, 2016. URL: https://doi.org/10.1145/2976002.2976007.
  29. Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1-13, 2008. URL: https://doi.org/10.1017/S0956796807006326.
  30. Erik Meijer. Confessions of a used programming language salesman. In Richard P. Gabriel, David F. Bacon, Cristina Videira Lopes, and Guy L. Steele Jr., editors, Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2007, October 21-25, 2007, Montreal, Quebec, Canada, pages 677-694. ACM, 2007. URL: https://doi.org/10.1145/1297027.1297078.
  31. Erik Meijer. Your mouse is a database. Communications of the ACM, 55(5):66-73, 2012. URL: https://doi.org/10.1145/2160718.2160735.
  32. Erik Meijer, Brian Beckman, and Gavin M. Bierman. LINQ: reconciling object, relations and XML in the .NET framework. In Surajit Chaudhuri, Vagelis Hristidis, and Neoklis Polyzotis, editors, Proceedings of the ACM SIGMOD International Conference on Management of Data, Chicago, Illinois, USA, June 27-29, 2006, page 706. ACM, 2006. URL: https://doi.org/10.1145/1142473.1142552.
  33. Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348-375, 1978. URL: https://doi.org/10.1016/0022-0000(78)90014-4.
  34. Andrey Mokhov, Georgy Lukyanov, Simon Marlow, and Jerémie Dimino. Selective applicative functors. Proceedings of the ACM on Programming Languages, 3(ICFP):90:1-90:29, 2019. URL: https://doi.org/10.1145/3341694.
  35. Multicore OCaml. URL: https://github.com/ocaml-multicore/ocaml-multicore.
  36. Matthias Neubauer and Peter Thiemann. From sequential programs to multi-tier applications by program transformation. In Jens Palsberg and Martín Abadi, editors, Proceedings of the 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2005, Long Beach, California, USA, January 12-14, 2005, pages 221-232. ACM, 2005. URL: https://doi.org/10.1145/1040305.1040324.
  37. OCaml: Add "monadic" let operators. https://github.com/ocaml/ocaml/pull/1947, 2018.
  38. Dominic A. Orchard and Alan Mycroft. A notation for comonads. In Ralf Hinze, editor, Implementation and Application of Functional Languages - 24th International Symposium, IFL 2012, Oxford, UK, August 30 - September 1, 2012, Revised Selected Papers, volume 8241 of Lecture Notes in Computer Science, pages 1-17. Springer, 2012. URL: https://doi.org/10.1007/978-3-642-41582-1_1.
  39. Tomas Petricek and Don Syme. The F# computation expression zoo. In PADL, volume 8324 of Lecture Notes in Computer Science, pages 33-48. Springer, 2014. Google Scholar
  40. Frank Pfenning and Conal Elliott. Higher-order abstract syntax. In Richard L. Wexelblat, editor, Proceedings of the ACM SIGPLAN'88 Conference on Programming Language Design and Implementation (PLDI), Atlanta, Georgia, USA, June 22-24, 1988, pages 199-208. ACM, 1988. URL: https://doi.org/10.1145/53990.54010.
  41. Project Loom: Fibers and Continuations for the Java Virtual Machine. URL: https://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html.
  42. John C. Reynolds. Definitional interpreters for higher-order programming languages. In John J. Donovan and Rosemary Shields, editors, Proceedings of the ACM annual conference, ACM 1972, 1972, Volume 2, pages 717-740. ACM, 1972. URL: https://doi.org/10.1145/800194.805852.
  43. David Richter, David Kretzler, Pascal Weisenburger, Guido Salvaneschi, Sebastian Faust, and Mira Mezini. Prisma: A tierless language for enforcing contract-client protocols in decentralized applications (extended version). CoRR, abs/2205.07780, 2022. URL: https://doi.org/10.48550/arXiv.2205.07780.
  44. Scala async rfc. URL: http://docs.scala-lang.org/sips/pending/async.html.
  45. avocADO. Safe compile-time parallelization of for-comprehensions for Scala 3 . URL: https://github.com/kitlangton/parallel-for.
  46. Scala Computation Expressions. An implementation of Computation Expressions in Scala. URL: https://github.com/jedesah/computation-expressions.
  47. Coroutines is a library-level extension for the Scala programming language that introduces first-class coroutines. https://github.com/storm-enroute/coroutines, 2015.
  48. parallel-for. Automatically parallelize your for-comprehensions at compile time. URL: https://github.com/kitlangton/parallel-for.
  49. Scala workflow. Boilerplate-free syntax for computations with effects. URL: https://github.com/aztek/scala-workflow.
  50. Ruslan Shevchenko. dotty-cps-async - experimental CPS transformer for dotty. URL: https://github.com/rssh/dotty-cps-async.
  51. Don Syme, Tomas Petricek, and Dmitry Lomov. The F# asynchronous programming model. In Ricardo Rocha and John Launchbury, editors, Practical Aspects of Declarative Languages - 13th International Symposium, PADL 2011, Austin, TX, USA, January 24-25, 2011. Proceedings, volume 6539 of Lecture Notes in Computer Science, pages 175-189. Springer, 2011. URL: https://doi.org/10.1007/978-3-642-18378-2_15.
  52. Sebastian Ullrich and Leonardo de Moura. 'do' unchained: embracing local imperativity in a purely functional language (functional pearl). Proceedings of the ACM on Programming Languages, 6(ICFP):512-539, 2022. URL: https://doi.org/10.1145/3547640.
  53. Janis Voigtländer. Free theorems simply, via dinaturality. In Petra Hofstedt, Salvador Abreu, Ulrich John, Herbert Kuchen, and Dietmar Seipel, editors, Declarative Programming and Knowledge Management - Conference on Declarative Programming, DECLARE 2019, Unifying INAP, WLP, and WFLP, Cottbus, Germany, September 9-12, 2019, Revised Selected Papers, volume 12057 of Lecture Notes in Computer Science, pages 247-267. Springer, 2019. URL: https://doi.org/10.1007/978-3-030-46714-2_16.
  54. Philip Wadler. Theorems for free! In Joseph E. Stoy, editor, Proceedings of the fourth international conference on Functional programming languages and computer architecture, FPCA 1989, London, UK, September 11-13, 1989, pages 347-359. ACM, 1989. URL: https://doi.org/10.1145/99370.99404.
  55. Philip Wadler. Comprehending monads. Mathematical Structures in Computer Science, 2(4):461-493, 1992. URL: https://doi.org/10.1017/S0960129500001560.
  56. Jamie Willis, Nicolas Wu, and Matthew Pickering. Staged selective parser combinators. Proceedings of the ACM on Programming Languages, 4(ICFP):120:1-120:30, 2020. URL: https://doi.org/10.1145/3409002.
  57. Bo Yang. Dsl.scala - A framework to create embedded domain-specific languages in Scala. URL: https://github.com/ThoughtWorksInc/Dsl.scala.
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail