Type directed compilation of row-typed algebraic effects

Algebraic effect handlers, introduced by Plotkin and Power in 2002, are recently gaining in popularity as a purely functional approach to modeling effects. In this article, we give a full overview of practical algebraic effects in the context of a compiled implementation in the Koka language. In particular, we show how algebraic effects generalize over common constructs like exception handling, state, iterators and async-await. We give an effective type inference algorithm based on extensible effect rows using scoped labels, and a direct operational semantics. Finally, we show an efficient compilation scheme to common runtime platforms (like JavaScript) using a type directed selective CPS translation.

[1]  Chung-chieh Shan,et al.  Higher-order and Symbolic Computation Manuscript No. a Static Simulation of Dynamic Delimited Control , 2022 .

[2]  Martin Odersky,et al.  Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform , 2009, ICFP.

[3]  Daan Leijen,et al.  Madoko: Scholarly Documents for the Web , 2015, DocEng.

[4]  E. Meijer,et al.  Monadic parser combinators , 1996 .

[5]  Daan Leijen,et al.  From Monads to Effects and Back , 2016, PADL.

[6]  Andrej Bauer,et al.  Programming with algebraic effects and handlers , 2012, J. Log. Algebraic Methods Program..

[7]  S. Jones,et al.  A Transformation-Based Optimiser for Haskell , 1998, Sci. Comput. Program..

[8]  Gordon D. Plotkin,et al.  Handling Algebraic Effects , 2013, Log. Methods Comput. Sci..

[9]  Matija Pretnar Inferring Algebraic Effects , 2014, Log. Methods Comput. Sci..

[10]  Ohad Kammar,et al.  Handlers in action , 2013, ICFP.

[11]  Oleg Kiselyov,et al.  Freer monads, more extensible effects , 2015, Haskell.

[12]  Manuel Serrano,et al.  Hop Client-Side Compilation , 2007, Trends in Functional Programming.

[13]  Daan Leijen,et al.  Koka: Programming with Row Polymorphic Effect Types , 2014, MSFP.

[14]  Edwin Brady,et al.  Programming and reasoning with algebraic effects and dependent types , 2013, ICFP.

[15]  Tom Schrijvers,et al.  Effect handlers in scope , 2014, Haskell 2014.

[16]  Hayo Thielecke,et al.  Using a Continuation Twice and Its Implications for the Expressive Power of call/cc , 1999, High. Order Symb. Comput..

[17]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[18]  Shriram Krishnamurthi,et al.  Whalesong: running racket in the browser , 2013, DLS '13.

[19]  Lasse R. Nielsen A Selective CPS Transformation , 2001, MFPS.

[20]  Gordon D. Plotkin,et al.  Algebraic Operations and Generic Effects , 2003, Appl. Categorical Struct..

[21]  Andrzej Filinski Monads in action , 2010, POPL '10.

[22]  P. J. Landin,et al.  A Generalization of Jumps and Labels , 1998, High. Order Symb. Comput..

[23]  ShanChung-Chieh A static simulation of dynamic delimited control , 2007 .

[24]  Benedict R. Gaster,et al.  A Polymorphic Type System for Extensible Records and Variants , 1996 .

[25]  Olivier Danvy,et al.  Assessing the Overhead of ML Exceptions by Selective CPS Transformation , 1998 .

[26]  Jean-Yves Girard,et al.  The System F of Variable Types, Fifteen Years Later , 1986, Theor. Comput. Sci..

[27]  Daan Leijen,et al.  Parsec: direct style monadic parser combinators for the real world , 2001 .

[28]  James Cheney,et al.  Row-based effect types for database integration , 2012, TLDI '12.

[29]  Claudio V. Russo,et al.  Pause 'n' Play: Formalizing Asynchronous C# , 2012, ECOOP.

[30]  Sam Lindley,et al.  Liberating effects with rows and handlers , 2016, TyDe@ICFP.

[31]  Olivier Danvy,et al.  On one-pass CPS transformations , 2002, Journal of Functional Programming.

[32]  Michael Hicks,et al.  Lightweight monadic programming in ML , 2011, ICFP.

[33]  Daan Leijen,et al.  Extensible records with scoped labels , 2005, Trends in Functional Programming.

[34]  Yukiyoshi Kameyama,et al.  Polymorphic Delimited Continuations , 2007, APLAS.

[35]  Didier Rémy,et al.  Type inference for records in natural extension of ML , 1994 .

[36]  Andrej Bauer,et al.  An Effect System for Algebraic Effects and Handlers , 2014, Log. Methods Comput. Sci..

[37]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[38]  Olivier Danvy,et al.  Abstracting control , 1990, LISP and Functional Programming.

[39]  John H. Reppy Optimizing Nested Loops Using Local CPS Conversion , 2002, High. Order Symb. Comput..

[40]  Ohad Kammar,et al.  No value restriction is needed for algebraic effects and handlers* , 2016, Journal of Functional Programming.

[41]  Conor McBride,et al.  Do be do be do , 2017, POPL.

[42]  Amr Sabry,et al.  Extensible effects: an alternative to monad transformers , 2013, Haskell '13.

[43]  Olivier Danvy,et al.  CPS-transformation after strictness analysis , 1992, LOPL.

[44]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[45]  Marc Feeley,et al.  Efficient compilation of tail calls and continuations to JavaScript , 2012, Scheme '12.

[46]  Andrzej Filinski,et al.  Representing layered monads , 1999, POPL '99.

[47]  Olivier Danvy,et al.  A Functional Abstraction of Typed Contexts , 1989 .