10.1145/2500365.2500581acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Programming and reasoning with algebraic effects and dependent types

Published:25 September 2013Publication History

ABSTRACT

One often cited benefit of pure functional programming is that pure code is easier to test and reason about, both formally and informally. However, real programs have side-effects including state management, exceptions and interactions with the outside world. Haskell solves this problem using monads to capture details of possibly side-effecting computations --- it provides monads for capturing state, I/O, exceptions, non-determinism, libraries for practical purposes such as CGI and parsing, and many others, as well as monad transformers for combining multiple effects.

Unfortunately, useful as monads are, they do not compose very well. Monad transformers can quickly become unwieldy when there are lots of effects to manage, leading to a temptation in larger programs to combine everything into one coarse-grained state and exception monad. In this paper I describe an alternative approach based on handling algebraic effects, implemented in the IDRIS programming language. I show how to describe side effecting computations, how to write programs which compose multiple fine-grained effects, and how, using dependent types, we can use this approach to reason about states in effectful programs.

References

  1. J. Aldrich, J. Sunshine, D. Saini, and Z. Sparks. Typestate-oriented programming. In Proceedings of the 24th conference on Object Oriented Programming Systems Languages and Applications, pages 1015--1012, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. L. Augustsson and M. Carlsson. An exercise in dependent types: A well-typed interpreter, 1999. In Workshop on Dependent Types in Programming, Gothenburg.Google ScholarGoogle Scholar
  3. A. Bauer and M. Pretnar. Programming with Algebraic Effects and Handlers, 2012. Available from http://arxiv.org/abs/1203. 1539.Google ScholarGoogle Scholar
  4. E. Brady. Idris, a General Purpose Programming Language: Design and Implementation, 2013. Draft.Google ScholarGoogle Scholar
  5. E. Brady. Programming in Idris: a Tutorial, 2013. Available from http://idris-lang.org/tutorial.Google ScholarGoogle Scholar
  6. newblock {An exercise in dependent types: A well-typed interpreter}, 1999E. Brady and K. Hammond. A verified staged interpreter is a verified compiler. In Generative Programming and Component Engineering (GPCE 2006). ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. E. Brady and K. Hammond. Correct-by-construction concurrency: Using dependent types to verify implementations of effectful resource usage protocols. Fundamenta Informaticae, 102:145--176, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. E. Brady and K. Hammond. Scrapping your inefficient engine: Using partial evaluation to improve domain-specific language implementation. In Proceedings of the 15th International Conference on Functional Programming (ICFP '10), pages 297--308. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. E. Brady and K. Hammond. Resource-safe Systems Programming with Embedded Domain Specific Languages. In Practical Applications of Declarative Languages, pages 242--257, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Carette, O. Kiselyov, and C.-C. Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19(05):509--543. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. D. Delahaye. A tactic language for the system Coq. In Logic for Programming and Automated Reasoning (LPAR), volume 1955 of LNAI, pages 85--95. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. P. Hancock and A. Setzer. Interactive Programs in Dependent Type Theory. In Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic, pages 317--331, Aug. 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. M. Hyland, G. Plotkin, and J. Power. Combining effects: Sum and tensor. Theoretical Computer Science, 357:70--99, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. M. Jaskelioff. Modular monad transformers. In ESOP 09: Proceedings of the 18th European Symposium on Programming Languages and Systems, LNCS, pages 64--79. Springer, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. O. Kammar, S. Lindley, and N. Oury. Handlers in action. In Proceedings of the 18th International Conference on Functional Programming (ICFP '13). ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. P. B. Levy. Call-By-Push-Value. PhD thesis, Queen Mary and Westfield College, University of London, 2001.Google ScholarGoogle Scholar
  17. S. Liang, P. Hudak, and M. Jones. Monad transformers and modular interpreters. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages, pages 333--343, New York, New York, USA, Jan. 1995. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. B. Lippmeier. Witnessing Purity, Constancy and Mutability. In 7th Asian Symposium on Programming Languages and Systems (APLAS 2009), volume 5904 of LNCS, pages 95--110. Springer, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. C. McBride. Kleisli arrows of outrageous fortune, 2011. Draft.Google ScholarGoogle Scholar
  20. C. McBride and R. Paterson. Applicative programming with effects. Journal of functional programming, 18(1):1--13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. M. Michelbrink and A. Setzer. State dependent IO-monads in type theory. Electronic Notes in Theoretical Computer Science, 122:127--146, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. A. Nanevski, G. Morrisett, and L. Birkedal. Hoare type theory, polymorphism and separation. Journal of Functional Programming, 18(5--6):865--911, Sept. 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. A. Nanevski, G. Morrisett, A. Shinnar, P. Govereau, and L. Birkedal. Ynot: Dependent types for imperative programs. In Proceedings of the 13th International Conference on Functional Programming (ICFP '08), pages 229--240. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. M. Odersky, P. Altherr, V. Cremet, B. Emir, S. Maneth, S. Micheloud, N. Mihaylov, M. Schinz, E. Stenman, and M. Zenger. An overview of the Scala programming language. Technical report, 2004.Google ScholarGoogle Scholar
  25. E. Pasalic, W. Taha, and T. Sheard. Tagless staged interpreters for typed languages. In Proceedings of the 7th International Conference on Functional Programming (ICFP '02), volume 37, pages 218--229. ACM, Sept. 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. S. Peyton Jones. Haskell 98 Language and Libraries: The Revised Report. Technical report, 2002.Google ScholarGoogle Scholar
  27. G. Plotkin and M. Pretnar. Handlers of Algebraic Effects. In ESOP 09: Proceedings of the 18th European Symposium on Programming Languages and Systems, pages 80--94, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. M. Pretnar. The Logic and Handling of Algebraic Effects. PhD thesis, University of Edinburgh, 2010.Google ScholarGoogle Scholar
  29. R. Strom and S. Yemini. Typestate: A programming language concept for enhancing software reliability. IEEE Transactions on Software Engineering, SE-12(1):157--171, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. W. Swierstra. Data types a la carte. Journal of functional programming, 18(4):423--436, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. P. Wadler. Monads for functional programming. In J. Jeuring and E. Meijer, editors, Advanced Functional Programming, volume 925 of LNCS, pages 24--52. Springer, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. D. Walker. A Type System for Expressive Security Policies. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '00, pages 254--267. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. H. Xi. Imperative Programming with Dependent Types. In 15th Annual IEEE Symposium on Logic in Computer Science, pages 375--387, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Programming and reasoning with algebraic effects and dependent types

    Comments

    Login options

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

    Sign in
    • Published in

      cover image ACM Conferences
      ICFP '13: Proceedings of the 18th ACM SIGPLAN international conference on Functional programming
      September 2013
      484 pages
      ISBN:9781450323260
      DOI:10.1145/2500365

      Copyright © 2013 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 25 September 2013

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article

      Acceptance Rates

      ICFP '13 Paper Acceptance Rate 40 of 133 submissions, 30%Overall Acceptance Rate 305 of 979 submissions, 31%

      Upcoming Conference

      ICFP '23

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!