skip to main content
research-article
Open Access
Artifacts Evaluated & Functional

Capturing the future by replaying the past (functional pearl)

Published:30 July 2018Publication History
Skip Abstract Section

Abstract

Delimited continuations are the mother of all monads! So goes the slogan inspired by Filinski’s 1994 paper, which showed that delimited continuations can implement any monadic effect, letting the programmer use an effect as easily as if it was built into the language. It’s a shame that not many languages have delimited continuations.

Luckily, exceptions and state are also the mother of all monads! In this Pearl, we show how to implement delimited continuations in terms of exceptions and state, a construction we call thermometer continuations. While traditional implementations of delimited continuations require some way of ”capturing” an intermediate state of the computation, the insight of thermometer continuations is to reach this intermediate state by replaying the entire computation from the start, guiding it using a recording so that the same thing happens until the captured point.

Along the way, we explain delimited continuations and monadic reflection, show how the Filinski construction lets thermometer continuations express any monadic effect, share an elegant special-case for nondeterminism, and discuss why our construction is not prevented by theoretical results that exceptions and state cannot macro-express continuations.

Skip Supplemental Material Section

Supplemental Material

a76-koppel.webm

webm

85.9 MB

References

  1. Kenichi Asai and Oleg Kiselyov. 2011. Introduction to Programming with Shift and Reset. (2011). http://pllab.is.ocha.ac.jp/ ~asai/cw2011tutorial/main- e.pdfGoogle ScholarGoogle Scholar
  2. Alberto Gomez Corona. 2014. MFlow, a Continuation-Based Web Framework Without Continuations. (2014). https: //themonadreader.files.wordpress.com/2014/04/mflow.pdfGoogle ScholarGoogle Scholar
  3. Dan Piponi. 2008. The Mother of all Monads. http://blog.sigfpe.com/2008/12/mother- of- all- monads.html . (2008). Posted: 2008-12-24. Accessed: 2017-02-27.Google ScholarGoogle Scholar
  4. David Darais, Nicholas Labich, Phúc C Nguyen, and David Van Horn. 2017. Abstracting Definitional Interpreters (Functional Pearl). Proceedings of the ACM on Programming Languages 1, ICFP (2017), 12. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. R Kent Dyvbig, Simon Peyton Jones, and Amr Sabry. 2007. A Monadic Framework for Delimited Continuations. Journal of Functional Programming 17, 6 (2007), 687–730. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Mattias Felleisen. 1988. The Theory and Practice of First-Class Prompts. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 180–190. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Matthias Felleisen. 1990. On the Expressive Power of Programming Languages. (1990), 134–151. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Andrzej Filinski. 1994. Representing Monads. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’94). ACM, New York, NY, USA, 446–457. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Andrzej Filinski. 1999. Representing Layered Monads. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 175–188. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Michael Hanus, Herbert Kuchen, and Juan Jose Moreno-Navarro. 1995. Curry: A Truly Functional Logic Language. In Proc. ILPS, Vol. 95. 95–107.Google ScholarGoogle Scholar
  11. Ralf Hinze. 2012. Kan Extensions for Program Optimisation or: Art and Dan Explain an Old Trick. In International Conference on Mathematics of Program Construction. Springer, 324–362. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Oleg Kiselyov. 2010. Delimited Control in OCaml, Abstractly and Concretely: System Description. In International Symposium on Functional and Logic Programming. Springer, 304–320. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Oleg Kiselyov and KC Sivaramakrishnan. 2017. Eff directly in OCaml. In Post-proceedings of the ML workshop 2016. http://kcsrk.info/papers/caml- eff17.pdfGoogle ScholarGoogle Scholar
  14. James Koppel, Gabriel Scherer, and Armando Solar-Lezama. 2017. Capturing the Future by Replaying the Past. CoRR abs/1710.10385 (2017). arXiv: 1710.10385 http://arxiv.org/abs/1710.10385Google ScholarGoogle Scholar
  15. Mark Lillibridge. 1999. Unchecked Exceptions Can Be Strictly More Powerful Than Call/CC. Higher-Order and Symbolic Computation 12, 1 (1999), 75–104. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Greg Pettyjohn, John Clements, Joe Marshall, Shriram Krishnamurthi, and Matthias Felleisen. 2005. Continuations from Generalized Stack Inspection. In Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming (ICFP ’05). ACM, New York, NY, USA, 216–227. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Hayo Thielecke. 2001. Contrasting Exceptions and Continuations. Version available from http://www. cs. bham. ac. uk/hxt/research/exncontjournal. pdf (2001).Google ScholarGoogle Scholar
  18. Peter Thiemann. 2006. WASH Server Pages. In Functional and Logic Programming, 8th International Symposium, FLOPS 2006, Fuji-Susono, Japan, April 24-26, 2006, Proceedings. 277–293. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. TIOBE Software BV. 2017. TIOBE Index for February 2017. http://www.tiobe.com/tiobe- index/ . (2017). Posted: 2017-02-08. Accessed: 2017-02-22.Google ScholarGoogle Scholar

Index Terms

  1. Capturing the future by replaying the past (functional pearl)

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          • Published in

            cover image Proceedings of the ACM on Programming Languages
            Proceedings of the ACM on Programming Languages  Volume 2, Issue ICFP
            September 2018
            1133 pages
            EISSN:2475-1421
            DOI:10.1145/3243631
            Issue’s Table of Contents

            Copyright © 2018 Owner/Author

            This work is licensed under a Creative Commons Attribution International 4.0 License.

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 30 July 2018
            Published in pacmpl Volume 2, Issue ICFP

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader