Document Open Access Logo

ContextWorkflow: A Monadic DSL for Compensable and Interruptible Executions

Authors Hiroaki Inoue, Tomoyuki Aotani, Atsushi Igarashi

Thumbnail PDF


  • Filesize: 0.77 MB
  • 33 pages

Document Identifiers

Author Details

Hiroaki Inoue
  • Graduate School of Informatics, Kyoto University, Kyoto, Japan
Tomoyuki Aotani
  • School of Computing, Tokyo Institute of Technology, Tokyo, Japan
Atsushi Igarashi
  • Graduate School of Informatics, Kyoto University, Kyoto, Japan

Cite AsGet BibTex

Hiroaki Inoue, Tomoyuki Aotani, and Atsushi Igarashi. ContextWorkflow: A Monadic DSL for Compensable and Interruptible Executions. In 32nd European Conference on Object-Oriented Programming (ECOOP 2018). Leibniz International Proceedings in Informatics (LIPIcs), Volume 109, pp. 2:1-2:33, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2018)


Context-aware applications, whose behavior reactively depends on the time-varying status of the surrounding environment - such as network connection, battery level, and sensors - are getting more and more pervasive and important. The term "context-awareness" usually suggests prompt reactions to context changes: as the context change signals that the current execution cannot be continued, the application should immediately abort its execution, possibly does some clean-up tasks, and suspend until the context allows it to restart. Interruptions, or asynchronous exceptions, are useful to achieve context-awareness. It is, however, difficult to program with interruptions in a compositional way in most programming languages because their support is too primitive, relying on synchronous exception handling mechanism such as try-catch. We propose a new domain-specific language ContextWorkflow for interruptible programs as a solution to the problem. A basic unit of an interruptible program is a workflow, i.e., a sequence of atomic computations accompanied with compensation actions. The uniqueness of ContextWorkflow is that, during its execution, a workflow keeps watching the context between atomic actions and decides if the computation should be continued, aborted, or suspended. Our contribution of this paper is as follows; (1) the design of a workflow-like language with asynchronous interruption, checkpointing, sub-workflows and suspension; (2) a formal semantics of the core language; (3) a monadic interpreter corresponding to the semantics; and (4) its concrete implementation as an embedded domain-specific language in Scala.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Domain specific languages
  • workflow
  • asynchronous exception
  • checkpoint
  • monad
  • embedded domain specific language


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


  1. scalaz. URL:
  2. Monadless. URL:
  3. Gregory Abowd, Anind Dey, Peter Brown, Nigel Davies, Mark Smith, and Pete Steggles. Towards a better understanding of context and context-awareness. In Handheld and ubiquitous computing, volume 1707 of Springer LNCS, pages 304-307, 1999. Google Scholar
  4. Liliana Ardissono, Roberto Furnari, Anna Goy, Giovanna Petrone, and Marino Segnan. Context-aware workflow management. In International Conference on Web Engineering, volume 4607 of Springer LNCS, pages 47-52, 2007. Google Scholar
  5. Steve Awodey. Category Theory. Oxford University Press, Inc., 2nd edition, 2010. Google Scholar
  6. Engineer Bainomugisha, Andoni Lombide Carreton, Tom Van Cutsem, Stijn Mostinckx, and Wolfgang De Meuter. A survey on reactive programming. ACM Computing Surveys (CSUR), 45(4):52, 2013. Google Scholar
  7. Engineer Bainomugisha, Jorge Vallejos, Coen De Roover, Andoni Lombide Carreton, and Wolfgang De Meuter. Interruptible context-dependent executions: a fresh look at programming context-aware applications. In Proc. of ACM Onward! 2012, pages 67-84. ACM, 2012. Google Scholar
  8. Rúnar Óli Bjarnarson. Stackless scala with free monads. Scala Days, 2012. Google Scholar
  9. Roberto Bruni, Hernán Melgratti, and Ugo Montanari. Theoretical foundations for compensations in flow composition languages. In Proc. of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages Pages (POPL 2005), pages 209-220. ACM, 2005. Google Scholar
  10. Michael Butler, Tony Hoare, and Carla Ferreira. A trace semantics for long-running transactions. In Communicating Sequential Processes. The First 25 Years, volume 3525 of Springer LNCS, pages 133-150. Springer, 2005. Google Scholar
  11. Nelio Cacho, Fernando Castor Filho, Alessandro Garcia, and Eduardo Figueiredo. EJFlow: Taming exceptional control flows in aspect-oriented programming. In Proc. of AOSD'08, pages 72-83, New York, NY, USA, 2008. ACM. Google Scholar
  12. Christian Colombo and Gordon J. Pace. Recovery within long-running transactions. ACM Comput. Surv., 45(3):28:1-28:35, 2013. Google Scholar
  13. Melvin E Conway. Design of a separable transition-diagram compiler. Communications of the ACM, 6(7):396-408, 1963. Google Scholar
  14. Daniel Crawl and Ilkay Altintas. A provenance-based fault tolerance mechanism for scientific workflows. In Proc. of Provenance and Annotation of Data and Processes, volume 5272 of Springer LNCS, pages 152-159, 2008. Google Scholar
  15. Olivier Danvy and Andrzej Filinski. Abstracting control. In Proc. of Lisp and Functional Programming, pages 151-160, 1990. Google Scholar
  16. Ana Lúcia de Moura, Noemi Rodriguez, and Roberto Ierusalimschy. Coroutines in Lua. Journal of Universal Computer Science, 10(7):910-925, 2004. Google Scholar
  17. William R. Dieter and James E. Lumpp. A user-level checkpointing library for POSIX threads programs. In Fault-Tolerant Computing, 1999. Digest of Papers. Twenty-Ninth Annual International Symposium on, pages 224-227. IEEE, 1999. Google Scholar
  18. Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. Concurrent system programming with effect handlers. In Proceedings of the Symposium on Trends in Functional Programming, TFP, 2017. Google Scholar
  19. Conal Elliott and Paul Hudak. Functional reactive animation. In Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming, pages 263-273. ACM, 1997. Google Scholar
  20. Marc Feeley. Polling efficiently on stock hardware. In Proceedings of the conference on Functional programming languages and computer architecture, pages 179-187. ACM, 1993. Google Scholar
  21. Phil Freeman. Stack safety for free. URL:
  22. Hector Garcia-Molina and Kenneth Salem. Sagas. In Proc. of ACM SIGMOD, pages 249-259, New York, NY, USA, 1987. ACM. Google Scholar
  23. Jeremy Gibbons. Datatype-generic programming. In Datatype-Generic Programming, pages 1-71. Springer, 2007. Google Scholar
  24. Jim Gray. The transaction concept: Virtues and limitations. In Proceedings of the Seventh International Conference on Very Large Data Bases, pages 144-154, 1981. Google Scholar
  25. Sumit Gulwani, Krishna K. Mehra, and Trishul Chilimbi. Speed: Precise and efficient static estimation of program computational complexity. In Proc. of ACM POPL, pages 127-139, New York, NY, USA, 2009. ACM. Google Scholar
  26. Tim Harris, Simon Marlow, Simon Peyton-Jones, and Maurice Herlihy. Composable memory transactions. In Proceedings of the tenth ACM SIGPLAN symposium on Principles and practice of parallel programming, pages 48-60. ACM, 2005. Google Scholar
  27. William L. Harrison. The essence of multitasking. In International Conference on Algebraic Methodology and Software Technology, volume 4019 of Springer LNCS, pages 158-172. Springer, 2006. Google Scholar
  28. William L. Harrison, Gerard Allwein, Andy Gill, and Adam Procter. Asynchronous exceptions as an effect. In Proceedings of the 9th international conference on Mathematics of Program Construction, volume 5133 of Springer LNCS, pages 153-176. Springer-Verlag, 2008. Google Scholar
  29. Christopher T. Haynes, Daniel P. Friedman, and Mitchell Wand. Continuations and coroutines. In Proceedings of the 1984 ACM Symposium on LISP and functional programming, pages 293-298. ACM, 1984. Google Scholar
  30. Robert Hirschfeld, Pascal Costanza, and Oscar Nierstrasz. Context-oriented programming. Journal of Object Technology, 7(3):125-151, 2008. Google Scholar
  31. Paul Hudak. Building domain-specific embedded languages. ACM Computing Surveys (CSUR), 28(4es):196, 1996. Google Scholar
  32. Hiroaki Inoue, Tomoyuki Aotani, and Atsushi Igarashi. A DSL for compensable and interruptible executions. In Proceedings of the 4th ACM SIGPLAN International Workshop on Reactive and Event-Based Languages and Systems, REBLS 2017, pages 8-14, New York, NY, USA, 2017. ACM. Google Scholar
  33. Hiroaki Inoue and Atsushi Igarashi. A library-based approach to context-dependent computation with reactive values: Suppressing reactions of context-dependent functions using dynamic binding. In Companion Proc. of the 15th Intl. Conf. on Modularity, pages 50-54, New York, NY, USA, 2016. ACM. Google Scholar
  34. Roumen Kaiabachev, Walid Taha, and Angela Zhu. E-FRP with priorities. In Proceedings of the 7th ACM &IEEE international conference on Embedded software, pages 221-230. ACM, 2007. Google Scholar
  35. Gregor Kiczales, John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin. Aspect-oriented programming. In Mehmet Akşit and Satoshi Matsuoka, editors, Proc. of ECOOP, volume 1241 of Springer LNCS, pages 220-242. Springer, 1997. Google Scholar
  36. Oleg Kiselyov, Amr Sabry, and Cameron Swords. Extensible effects: An alternative to monad transformers. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Haskell '13, pages 59-70, New York, NY, USA, 2013. ACM. Google Scholar
  37. Eric Koskinen and Maurice Herlihy. Checkpoints and continuations instead of nested transactions. In Proceedings of the twentieth annual symposium on Parallelism in algorithms and architectures, pages 160-168. ACM, 2008. Google Scholar
  38. Jing Li, Huibiao Zhu, Geguang Pu, and Jifeng He. Looking into compensable transactions. In Software Engineering Workshop, 2007. SEW 2007. 31st IEEE, pages 154-166. IEEE, 2007. Google Scholar
  39. Bertram Ludäscher, Ilkay Altintas, Chad Berkley, Dan Higgins, Efrat Jaeger, Matthew Jones, Edward A Lee, Jing Tao, and Yang Zhao. Scientific workflow management and the Kepler system. Concurrency and Computation: Practice and Experience, 18(10):1039-1065, 2006. Google Scholar
  40. Simon Marlow, Simon Peyton Jones, Andrew Moran, and John Reppy. Asynchronous exceptions in Haskell. In Proc. of ACM PLDI, pages 274-285, New York, NY, USA, 2001. ACM. Google Scholar
  41. Microsoft. Powershell documentation. URL:
  42. Microsoft. Windows workflow foundation. URL:
  43. Eugenio Moggi. Computational lambda-calculus and monads. In Logic in Computer Science, 1989. LICS'89, Proceedings., Fourth Annual Symposium on, pages 14-23. IEEE, 1989. Google Scholar
  44. N.C. Narendra and S Gundugola. Automated context-aware adaptation of web service executions. In Proceedings of the IEEE International Conference on Computer Systems and Applications, pages 179-187. IEEE Computer Society, 2006. Google Scholar
  45. Bruno C. d. S. Oliveira and Jeremy Gibbons. Scala for generic programmers: comparing Haskell and Scala support for generic programming. Journal of functional programming, 20(3-4):303-352, 2010. Google Scholar
  46. Maciej Piróg and Jeremy Gibbons. The coinductive resumption monad. In Mathematical Foundations of Programming Semantics Thirtieth Annual Conference, page 273, 2014. Google Scholar
  47. Ganesan Ramalingam and Kapil Vaswani. Fault tolerance via idempotence. In Proc. of ACM POPL, POPL '13, pages 249-262, New York, NY, USA, 2013. ACM. Google Scholar
  48. Brian Randell, Peter Lee, and Philip C. Treleaven. Reliability issues in computing system design. ACM Computing Surveys (CSUR), 10(2):123-165, 1978. Google Scholar
  49. Tiark Rompf, Ingo Maier, and Martin Odersky. Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP '09, pages 317-328. ACM, 2009. Google Scholar
  50. Algis Rudys and Dan S. Wallach. Termination in language-based systems. ACM Transactions on Information and System Security (TISSEC), 5(2):138-168, 2002. Google Scholar
  51. Guido Salvaneschi, Gerold Hintz, and Mira Mezini. REScala: Bridging between object-oriented and functional style in reactive applications. In Proc. of Intl. Conf. on Modularity, pages 25-36. ACM, 2014. Google Scholar
  52. STM Scala. Expert group. scalastm. web, 2011. URL:
  53. Nir Shavit and Dan Touitou. Software transactional memory. Distributed Computing, 10(2):99-116, 1997. Google Scholar
  54. Sucha Smanchat, Sea Ling, and Maria Indrawan. A survey on context-aware workflow adaptations. In Proceedings of the 6th International Conference on Advances in Mobile Computing and Multimedia, pages 414-417. ACM, 2008. Google Scholar
  55. Michael Sperber, R. Kent Dybvig, Matthew Flatt, Anton Van Straaten, Robby Findler, and Jacob Matthews. Revised⁶ report on the algorithmic language Scheme. Journal of Functional Programming, 19(S1):1-301, 2009. Google Scholar
  56. Janis Voigtländer. Asymptotic improvement of computations over free monads. In Proceedings of the 9th International Conference on Mathematics of Program Construction, pages 388-403. Springer-Verlag, 2008. Google Scholar
  57. Martin von Löwis, Marcus Denker, and Oscar Nierstrasz. Context-oriented programming: Beyond layers. In Proc. of Intl. Conf. on Dynamic Languages, pages 143-156, New York, NY, USA, 2007. ACM. Google Scholar
  58. Philip Wadler. Monads for functional programming. In International School on Advanced Functional Programming, pages 24-52. Springer, 1995. Google Scholar
  59. Zhanyong Wan, Walid Taha, and Paul Hudak. Event-driven FRP. In International Symposium on Practical Aspects of Declarative Languages, pages 155-172. Springer, 2002. Google Scholar
  60. Westley Weimer. Exception-handling bugs in Java and a language extension to avoid them. In Advanced Topics in Exception Handling Techniques, volume 4119 of Springer LNCS, pages 22-41, 2006. Google Scholar
  61. Tetsuo Yokoyama and Robert Glück. A reversible programming language and its invertible self-interpreter. In Proc. ACM PEPM, pages 144-153, New York, NY, USA, 2007. ACM. Google Scholar
  62. Lukasz Ziarek and Suresh Jagannathan. Lightweight checkpointing for concurrent ML. Journal of Functional Programming, 20(2):137-173, 2010. Google Scholar
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