Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article

Freer monads, more extensible effects

Published: 30 August 2015 Publication History
  • Get Citation Alerts
  • Abstract

    We present a rational reconstruction of extensible effects, the recently proposed alternative to monad transformers, as the confluence of efforts to make effectful computations compose. Free monads and then extensible effects emerge from the straightforward term representation of an effectful computation, as more and more boilerplate is abstracted away. The generalization process further leads to freer monads, constructed without the Functor constraint. The continuation exposed in freer monads can then be represented as an efficient type-aligned data structure. The end result is the algorithmically efficient extensible effects library, which is not only more comprehensible but also faster than earlier implementations. As an illustration of the new library, we show three surprisingly simple applications: non-determinism with committed choice (LogicT), catching IO exceptions in the presence of other effects, and the semi-automatic management of file handles and other resources through monadic regions. We extensively use and promote the new sort of `laziness', which underlies the left Kan extension: instead of performing an operation, keep its operands and pretend it is done.

    References

    [1]
    H. Apfelmus. The Operational monad tutorial. The Monad.Reader, 15:37–56, 2010.
    [2]
    S. Awodey. Category Theory, volume 49 of Oxford Logic Guides. Oxford University Press, 2006.
    [3]
    P. Bahr. Composing and decomposing data types: a closed type families implementation of data types à la carte. In WGP@ICFP, pages 71–82. ACM Press, 31 Aug. 2014.
    [4]
    A. Bauer and M. Pretnar. Programming with algebraic effects and handlers. arXiv:1203.1539 {cs.PL}, 2012.
    [5]
    J.-P. Bernardy and N. Pouillard. Names for free: polymorphic views of names and binders. In Haskell {11}, pages 13–24.
    [6]
    E. Brady. Programming and reasoning with algebraic effects and dependent types. In ICFP {15}, pages 133–144.
    [7]
    R. Cartwright and M. Felleisen. Extensible denotational language specifications. In M. Hagiya and J. C. Mitchell, editors, Theor. Aspects of Comp. Soft., number 789 in LNCS, pages 244–272. Springer, 1994.
    [8]
    K. Claessen. Parallel parsing processes. J. Functional Programming, 14(6):741–757, 2004.
    [9]
    O. Danvy and A. Filinski. Abstracting control. In Proceedings of the 1990 ACM Conference on Lisp and Functional Programming, pages 151–160. ACM Press, 27–29 June 1990.
    [10]
    M. Fluet and J. G. Morrisett. Monadic regions. J. Functional Programming, 16(4–5):485–545, 2006.
    [11]
    Haskell. Haskell Symposium, 2013. ACM.
    [12]
    Haskell. Haskell Symposium, 2014. ACM.
    [13]
    R. Hinze. Deriving backtracking monad transformers. In ICFP ’00, pages 186–197. ACM Press, 2000.
    [14]
    J. Hughes. The design of a pretty-printing library. In First Intl. Spring School on Adv. Functional Programming Techniques, pages 53–96, London, UK, UK, 1995. Springer-Verlag.
    [15]
    ICFP. ICFP ’13, 2013. ACM Press.
    [16]
    P. Johann and N. Ghani. Foundations for structured programming with GADTs. In POPL ’08, pages 297–308. ACM Press, 2008.
    [17]
    O. Kammar, S. Lindley, and N. Oury. Handlers in action. In ICFP
    [18]
    , pages 145–158.
    [19]
    O. Kiselyov. Iteratees. In Proc. of the 11th International Symposium on Functional and Logic Programming, pages 166–181, 2012.
    [20]
    O. Kiselyov and C.-c. Shan. Lightweight monadic regions. In Proc. 2008 Haskell Symposium, pages 1–12. ACM Press, 2008.
    [21]
    O. Kiselyov, C.-c. Shan, D. P. Friedman, and A. Sabry. Backtracking, interleaving, and terminating monad transformers (functional pearl). In ICFP ’05, pages 192–203. ACM Press, Sept. 2005.
    [22]
    O. Kiselyov, A. Sabry, and C. Swords. Extensible effects: an alternative to monad transformers. In Haskell {11}, pages 59–70.
    [23]
    S. Liang, P. Hudak, and M. Jones. Monad transformers and modular interpreters. In POPL ’95, pages 333–343. ACM Press, 1995.
    [24]
    C.-k. Lin. Programming monads operationally with Unimo. In ICFP ’06, pages 274–285. ACM Press, 2006.
    [25]
    C. Lüth and N. Ghani. Composing monads using coproducts. In ICFP ’02, pages 133–144. ACM Press, 2002.
    [26]
    L. Naish. Pruning in logic programming. Technical Report 95/16, Department of Computer Science, University of Melbourne, 1995.
    [27]
    G. Plotkin and M. Pretnar. Handlers of algebraic effects. In ESOP ’09, pages 80–94, Berlin, Heidelberg, 2009. Springer-Verlag.
    [28]
    N. Sculthorpe, J. Bracker, G. Giorgidze, and A. Gill. The constrainedmonad problem. In ICFP {15}, pages 287–298.
    [29]
    T. Sheard and E. Paˇsali´c. Two-level types and parameterized modules. J. Functional Programming, 14(5):547–587, Sept. 2004.
    [30]
    G. L. Steele, Jr. Building interpreters by composing monads. In POPL ’94, pages 472–492. ACM Press, 1994.
    [31]
    W. Swierstra. Data types à la carte. J. Funct. Program., 18(4):423– 436, July 2008.
    [32]
    A. van der Ploeg and O. Kiselyov. Reflection without remorse: revealing a hidden sequence to speed up monadic reflection. In Haskell {12}, pages 133–144.
    [33]
    N. Wu and T. Schrijvers. Fusion for free: Efficient algebraic effect handlers. In MPC 2015, 2015. URL /Research/papers/mpc2015.
    [35]
    N. Wu, T. Schrijvers, and R. Hinze. Effect handlers in scope. In Haskell {12}, pages 1–12.

    Cited By

    View all
    • (2024)A framework for higher-order effects & handlersScience of Computer Programming10.1016/j.scico.2024.103086234:COnline publication date: 1-May-2024
    • (2023)From Capabilities to Regions: Enabling Efficient Compilation of Lexical Effect HandlersProceedings of the ACM on Programming Languages10.1145/36228317:OOPSLA2(941-970)Online publication date: 16-Oct-2023
    • (2023)Modular Models of Monoids with OperationsProceedings of the ACM on Programming Languages10.1145/36078507:ICFP(566-603)Online publication date: 31-Aug-2023
    • Show More Cited By

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 50, Issue 12
    Haskell '15
    December 2015
    212 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/2887747
    Issue’s Table of Contents
    • cover image ACM Conferences
      Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell
      August 2015
      212 pages
      ISBN:9781450338080
      DOI:10.1145/2804302
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 30 August 2015
    Published in SIGPLAN Volume 50, Issue 12

    Check for updates

    Author Tags

    1. Kan extension
    2. coroutine
    3. effect handler
    4. effect interaction
    5. free monad
    6. open union
    7. type and effect system

    Qualifiers

    • Research-article

    Funding Sources

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)86
    • Downloads (Last 6 weeks)9
    Reflects downloads up to 09 Aug 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)A framework for higher-order effects & handlersScience of Computer Programming10.1016/j.scico.2024.103086234:COnline publication date: 1-May-2024
    • (2023)From Capabilities to Regions: Enabling Efficient Compilation of Lexical Effect HandlersProceedings of the ACM on Programming Languages10.1145/36228317:OOPSLA2(941-970)Online publication date: 16-Oct-2023
    • (2023)Modular Models of Monoids with OperationsProceedings of the ACM on Programming Languages10.1145/36078507:ICFP(566-603)Online publication date: 31-Aug-2023
    • (2023)Reflecting on Random GenerationProceedings of the ACM on Programming Languages10.1145/36078427:ICFP(322-355)Online publication date: 31-Aug-2023
    • (2023)Minimally Invasive Generation of RISC-V Instruction Set Simulators from Formal ISA Models2023 Forum on Specification & Design Languages (FDL)10.1109/FDL59689.2023.10272224(1-8)Online publication date: 13-Sep-2023
    • (2023)Versatile and Flexible Modelling of the RISC-V Instruction Set ArchitectureTrends in Functional Programming10.1007/978-3-031-38938-2_2(16-35)Online publication date: 12-Jan-2023
    • (2022)Parsing randomnessProceedings of the ACM on Programming Languages10.1145/35632916:OOPSLA2(89-113)Online publication date: 31-Oct-2022
    • (2022)Formal reasoning about layered monadic interpretersProceedings of the ACM on Programming Languages10.1145/35476306:ICFP(254-282)Online publication date: 31-Aug-2022
    • (2022)Algebraic Effects for Extensible Dynamic SemanticsJournal of Logic, Language and Information10.1007/s10849-022-09378-732:2(219-245)Online publication date: 26-Aug-2022
    • (2022)Region-based Resource Management and Lexical Exception Handlers in Continuation-Passing StyleProgramming Languages and Systems10.1007/978-3-030-99336-8_18(492-519)Online publication date: 29-Mar-2022
    • Show More Cited By

    View Options

    Get Access

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media