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
- 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 Scholar
Digital Library
- L. Augustsson and M. Carlsson. An exercise in dependent types: A well-typed interpreter, 1999. In Workshop on Dependent Types in Programming, Gothenburg.Google Scholar
- A. Bauer and M. Pretnar. Programming with Algebraic Effects and Handlers, 2012. Available from http://arxiv.org/abs/1203. 1539.Google Scholar
- E. Brady. Idris, a General Purpose Programming Language: Design and Implementation, 2013. Draft.Google Scholar
- E. Brady. Programming in Idris: a Tutorial, 2013. Available from http://idris-lang.org/tutorial.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- M. Hyland, G. Plotkin, and J. Power. Combining effects: Sum and tensor. Theoretical Computer Science, 357:70--99, 2006. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- P. B. Levy. Call-By-Push-Value. PhD thesis, Queen Mary and Westfield College, University of London, 2001.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- C. McBride. Kleisli arrows of outrageous fortune, 2011. Draft.Google Scholar
- C. McBride and R. Paterson. Applicative programming with effects. Journal of functional programming, 18(1):1--13, 2008. Google Scholar
Digital Library
- M. Michelbrink and A. Setzer. State dependent IO-monads in type theory. Electronic Notes in Theoretical Computer Science, 122:127--146, 2005. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- S. Peyton Jones. Haskell 98 Language and Libraries: The Revised Report. Technical report, 2002.Google Scholar
- 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 Scholar
Digital Library
- M. Pretnar. The Logic and Handling of Algebraic Effects. PhD thesis, University of Edinburgh, 2010.Google Scholar
- 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 Scholar
Digital Library
- W. Swierstra. Data types a la carte. Journal of functional programming, 18(4):423--436, 2008. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- H. Xi. Imperative Programming with Dependent Types. In 15th Annual IEEE Symposium on Logic in Computer Science, pages 375--387, 2000. Google Scholar
Digital Library
Index Terms
Programming and reasoning with algebraic effects and dependent types






Comments