Abstract
We study algebraic computational effects and their handlers in the dependently typed setting. We describe computational effects using a generalisation of Plotkin and Pretnar's effect theories, whose dependently typed operations allow us to capture precise notions of computation, e.g., state with location-dependent store types and dependently typed update monads. Our treatment of handlers is based on an observation that their conventional term-level definition leads to unsound program equivalences being derivable in languages that include a notion of homomorphism. We solve this problem by giving handlers a novel type-based treatment via a new computation type, the user-defined algebra type, which pairs a value type (the carrier) with a set of value terms (the operations), capturing Plotkin and Pretnar's insight that effect handlers denote algebras. We then show that the conventional presentation of handlers can be routinely derived, and demonstrate that this type-based treatment of handlers provides a useful mechanism for reasoning about effectful computations. We also equip the resulting language with a sound denotational semantics based on families fibrations.
Supplemental Material
- J. Adamek and J. Rosicky. 1994. Locally Presentable and Accessible Categories. Number 189 in London Mathematical Society Lecture Note Series. Cambridge Univ. Press. Google Scholar
Cross Ref
- D. Ahman. 2017. Fibred Computational Effects. Ph.D. Dissertation. School of Informatics, University of Edinburgh.Google Scholar
- D. Ahman, J. Chapman, and T. Uustalu. 2014. When is a container a comonad? Logical Methods in Computer Science 10, 3 (2014). Google Scholar
Cross Ref
- D. Ahman, N. Ghani, and G. D. Plotkin. 2016. Dependent Types and Fibred Computational Effects. In Proc. of 19th Int. Conf. on Foundations of Software Science and Computation Structures, FoSSaCS 2016 (LNCS), Vol. 9634. Springer, 1–19. Google Scholar
Cross Ref
- D. Ahman, C. Hriţcu, K. Maillard, G. Martínez, G. Plotkin, J. Protzenko, A. Rastogi, and N. Swamy. 2017. Dijkstra Monads for Free. In Proc. of 44th ACM SIGPLAN Symp. on Principles of Programming Languages, POPL 2017. ACM, 515–529. Google Scholar
Digital Library
- D. Ahman and S. Staton. 2013. Normalization by Evaluation and Algebraic Effects. In Proc. of 29th Conf. on the Mathematical Foundations of Programming Semantics, MFPS XXIX (ENTCS), Vol. 298. Elsevier, 51–69. Google Scholar
Digital Library
- D. Ahman and T. Uustalu. 2014. Update Monads: Cointerpreting Directed Containers. In Post-proc. of 19th Meeting “Types for Proofs and Programs", TYPES 2013 (LIPIcs), Vol. 26. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl Publishing, 1–23.Google Scholar
- A. Bauer and M. Pretnar. 2015. Programming with algebraic effects and handlers. J. Log. Algebr. Meth. Program. 84, 1 (2015), 108–123. Google Scholar
Cross Ref
- E. Brady. 2013. Programming and reasoning with algebraic effects and dependent types. In Proc. of 18th ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 2013. ACM, 133–144. Google Scholar
Digital Library
- C. Casinghino. 2014. Combining Proofs and Programs. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- E. W. Dijkstra. 1975. Guarded Commands, Nondeterminacy and Formal Derivation of Programs. CACM 18, 8 (1975), 5.Google Scholar
Digital Library
- P. Dybjer and A. Setzer. 1999. A Finite Axiomatization of Inductive-Recursive Definitions. In Proc. 4th Int. Conf. on Typed Lambda Calculi and Applications, TLCA’99 (LNCS), Vol. 1581. Springer, 129–146. Google Scholar
Cross Ref
- J. Egger, R. E. Møgelberg, and A. Simpson. 2014. The enriched effect calculus: syntax and semantics. J. Log. Comput. 24, 3 (2014), 615–654. Google Scholar
Cross Ref
- N. Ghani, L. Malatesta, F. N. Forsberg, and A. Setzer. 2013. Fibred Data Types. In Proc. of 28th Ann. Symp. on Logic in Computer Science, LICS 2013. IEEE Computer Society, 243–252. Google Scholar
Digital Library
- G. A. Grätzer. 1979. Universal Algebra (2nd ed.). Springer.Google Scholar
- P. Hancock and A. Setzer. 2000. Interactive programs in dependent type theory. In Proc. of 14th Ann. Conf. of the EACSL on Computer Science Logic, CSL 2000 (LNCS), Vol. 1862. Springer, 317–331. Google Scholar
Cross Ref
- M. Hedberg. 1998. A Coherence Theorem for Martin-Löf ’s Type Theory. J. Funct. Program. 8, 4 (1998), 413–436. Google Scholar
Digital Library
- D. Hillerström and S. Lindley. 2016. Liberating Effects with Rows and Handlers. In Proc. of 1st Wksh. on Type-Driven Development, TyDe 2016. ACM, 15–27. Google Scholar
Digital Library
- M. Hofmann. 1995. Extensional concepts in intensional type theory. Ph.D. Dissertation. Laboratory for Foundations in Computer Science, University of Edinburgh.Google Scholar
- M. Hofmann. 1997. Syntax and Semantics of Dependent Types. In Semantics and Logics of Computation. Cambridge Univ. Press, 79–130. Google Scholar
Cross Ref
- K. Honda, V. T. Vasconcelos, and M. Kubo. 1998. Language Primitives and Type Discipline for Structured CommunicationBased Programming. In Proc. of 7th European Symp. on Programming, ESOP 1998 (LNCS), Vol. 1381. Springer, 122–138.Google Scholar
- M. Hyland, G. Plotkin, and J. Power. 2006. Combining effects: Sum and tensor. Theor. Comput. Sci. 357, 1–3 (2006), 70–99.Google Scholar
Digital Library
- B. Jacobs. 1999. Categorical Logic and Type Theory. Number 141 in Studies in Logic and the Foundations of Mathematics. North Holland, Elsevier.Google Scholar
- O. Kammar, S. Lindley, and N. Oury. 2013. Handlers in Action. In Proc. of 18th ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 2013. ACM, 145–158. Google Scholar
Digital Library
- O. Kammar and G. D. Plotkin. 2012. Algebraic Foundations for Effect-dependent Optimisations. In Proc. of 39th ACM SIGPLAN-SIGACT Symp. on Principles of Programming Languages, POPL 2012. ACM, 349–360. Google Scholar
Digital Library
- D. Leijen. 2017. Type Directed Compilation of Row-Typed Algebraic Effects. In Proc. of 44th ACM SIGPLAN Symp. on Principles of Programming Languages, POPL 2017. ACM, 486–499. Google Scholar
Digital Library
- P. B. Levy. 2004. Call-By-Push-Value: A Functional/Imperative Synthesis. Semantics Structures in Computation, Vol. 2. Springer.Google Scholar
- P. B. Levy. 2006. Monads and Adjunctions for Global Exceptions. ENTCS 158 (2006), 261–287. Google Scholar
Digital Library
- P. B. Levy. 2017. Contextual isomorphisms. In Proc. of 44th ACM SIGPLAN Symp. on Principles of Programming Languages, POPL 2017. ACM, 400–414. Google Scholar
Digital Library
- S. Lindley, C. McBride, and C. McLaughlin. 2017. Do Be Do Be Do. In Proc. of 44th ACM SIGPLAN Symp. on Principles of Programming Languages, POPL 2017. ACM, 500–514.Google Scholar
- P. Martin-Löf. 1975. An intuitionisitc theory of types, Predicative part. In Proc. of Logic Colloquium 1973. North-Holland, 73–118.Google Scholar
- P. Martin-Löf. 1984. Intuitionistic Type Theory. Bibliopolis.Google Scholar
- C. McBride. 2011. Functional Pearl: Kleisli arrows of outrageous fortune. J. Funct. Program. (2011). (To appear).Google Scholar
- E. Moggi. 1989. Computational Lambda-Calculus and Monads. In Proc. of 4th Ann. Symp. on Logic in Computer Science, LICS 1989. IEEE, 14–23. Google Scholar
Cross Ref
- E. Moggi. 1991. Notions of Computation and Monads. Inf. Comput. 93, 1 (1991), 55–92. Google Scholar
Digital Library
- G. Munch-Maccagnoni. 2013. Syntax and Models of a non-Associative Composition of Programs and Proofs. Ph.D. Dissertation. Univ. Paris Diderot.Google Scholar
- A. Nanevski, G. Morrisett, and L. Birkedal. 2008. Hoare Type Theory, polymorphism and separation. J. Funct. Program. 18, 5-6 (2008), 865–911.Google Scholar
Digital Library
- M. Okada and P. J. Scott. 1999. A Note on Rewriting Theory for Uniqueness of Iteration. Theory Appl. Categ. 6, 4 (1999), 47–64.Google Scholar
- P.-M. Pédrot and N. Tabareau. 2017. An Effectful Way to Eliminate Addiction to Dependence. In Proc. of 32nd Ann. Symp. on Logic in Computer Science, LICS 2017. 1–12. Google Scholar
Cross Ref
- A. M. Pitts. 1991. Evaluation Logic. In Proc. IVth Higher Order Workshop (Workshops in Computing). Springer, 162–189. Google Scholar
Cross Ref
- A. M. Pitts, J. Matthiesen, and J. Derikx. 2015. A Dependent Type Theory with Abstractable Names. In Proc. of 9th Wksh. on Logical and Semantic Frameworks, with Applications, LSFA 2014 (ENTCS), Vol. 312. Elsevier, 19–50. Google Scholar
Digital Library
- G. Plotkin and J. Power. 2001. Semantics for Algebraic Operations. In Proc. of 17th Conf. on the Mathematical Foundations of Programming Semantics, MFPS XVII (ENTCS), Vol. 45. Elsevier, 332–345. Google Scholar
Cross Ref
- G. D. Plotkin and J. Power. 2002. Notions of Computation Determine Monads. In Proc. of 5th Int. Conf. on Foundations of Software Science and Computation Structures, FOSSACS 2002 (LNCS), Vol. 2303. Springer, 342–356. Google Scholar
Cross Ref
- G. D. Plotkin and M. Pretnar. 2008. A Logic for Algebraic Effects. In Proc. of 23th Ann. IEEE Symp. on Logic in Computer Science, LICS 2008. IEEE, 118–129. Google Scholar
Digital Library
- G. D. Plotkin and M. Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science 9, 4:23 (2013).Google Scholar
- J. Power. 2006. Countable Lawvere Theories and Computational Effects. In Proc. of 3rd Irish Conf. on the Mathematical Foundations of Computer Science and Information Technology, MFCSIT 2004 (ENTCS), Vol. 161. Elsevier, 59–71. Google Scholar
Cross Ref
- S. Staton. 2013. Instances of Computational Effects: An Algebraic Perspective. In Proc. of 28th Ann. ACM/IEEE Symp. on Logic in Computer Science, LICS 2013. IEEE, 519–519. Google Scholar
Digital Library
- T. Streicher. 1991. Semantics of Type Theory. Correctness, Completeness and Independence Results. Birkhäuser Boston. Google Scholar
Cross Ref
- The Agda Team. 2017. The Agda Wiki. Available at http://appserv.cs.chalmers.se/users/ulfn/wiki/agda.php . (2017).Google Scholar
- The Univalent Foundations Program. 2013. Homotopy Type Theory: Univalent Foundations of Mathematics. Institute for Advanced Study. Available at: https://homotopytypetheory.org/book/ .Google Scholar
Index Terms
Handling fibred algebraic effects
Recommendations
Algebraic effects and effect handlers for idioms and arrows
WGP '14: Proceedings of the 10th ACM SIGPLAN workshop on Generic programmingPlotkin and Power's algebraic effects combined with Plotkin and Pretnar's effect handlers provide a foundation for modular programming with effects. We present a generalisation of algebraic effects and effect handlers to support other kinds of effectful ...
Normalization by Evaluation and Algebraic Effects
We examine the interplay between computational effects and higher types. We do this by presenting a normalization by evaluation algorithm for a language with function types as well as computational effects. We use algebraic theories to treat the ...
Programming and reasoning with algebraic effects and dependent types
ICFP '13One 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 ...






Comments