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

Reflection without remorse: revealing a hidden sequence to speed up monadic reflection

Published: 03 September 2014 Publication History
  • Get Citation Alerts
  • Abstract

    A series of list appends or monadic binds for many monads performs algorithmically worse when left-associated. Continuation-passing style (CPS) is well-known to cure this severe dependence of performance on the association pattern. The advantage of CPS dwindles or disappears if we have to examine or modify the intermediate result of a series of appends or binds, before continuing the series. Such examination is frequently needed, for example, to control search in non-determinism monads.
    We present an alternative approach that is just as general as CPS but more robust: it makes series of binds and other such operations efficient regardless of the association pattern-- and also provides efficient access to intermediate results. The key is to represent such a conceptual sequence as an efficient sequence data structure. Efficient sequence data structures from the literature are homogeneous and cannot be applied as they are in a type-safe way to series of monadic binds. We generalize them to type aligned sequences and show how to construct their (assuredly order-preserving) implementations. We demonstrate that our solution solves previously undocumented, severe performance problems in iteratees, LogicT transformers, free monads and extensible effects.

    References

    [1]
    S. Awodey. Category theory. Oxford University Press, 2006.
    [2]
    M. Blažević. Coroutine pipelines. The Monad Reader, 19: 29--50, 2011.
    [3]
    J. Cheney and R. Hinze. First-class phantom types. Technical report, Cornell University, 2003.
    [4]
    K. Claessen. Functional pearl: Parallel parsing processes. J. of Functional Programming, 14: 741--757, 2004.
    [5]
    R. K. Dyvbig, S. Peyton Jones, and A. Sabry. A monadic framework for delimited continuations. J. of Functional Programming, 17 (6): 687--730, 2007.
    [6]
    A. Filinski. Representing monads. In Proc. of the 21th Symposium on Principles of Programming Languages, pages 446--457, 1994.
    [7]
    D. P. Friedman. The mystery of the tower revealed: A nonreflective description of the reflective tower. LISP and Symbolic Computation, 1 (1): 298--307, 1988.
    [8]
    R. Hinze. Deriving backtracking monad transformers. In Proc. of the 5th International Conference on Functional Programming, pages 186--197, 2000.
    [9]
    R. Hinze and R. Paterson. Finger trees: A simple general-purpose data structure. J. Funct. Program., 16 (2): 197--217, 2006.
    [10]
    J. Hughes. A novel representation of lists and its application to the function 'reverse'. Information Processing Letters, 22 (3): 141--144, 1986.
    [11]
    M. Jaskelioff. Modular monad transformers. In Transactions on Programming Languages and Systems, pages 64--79, 2009.
    [12]
    M. P. Jones and L. Duponcheel. Composing monads. Research Report YALEU/DCS/RR-1004, Yale University, 1993.
    [13]
    O. Kammar, S. Lindley, and N. Oury. Handlers in action. In Proc. of the 18th International Conference on Functional Programming, 2013.
    [14]
    H. Kaplan and R. E. Tarjan. Purely functional, real-time deques with catenation. J. of the ACM, 46 (5): 577--603, 1999.
    [15]
    O. Kiselyov. Iteratees. In Proc. of the 11th International Symposium on Functional and Logic Programming, pages 166--181, 2012.
    [16]
    O. Kiselyov, C. Shan, D. P. Friedman, and A. Sabry. Backtracking, interleaving, and terminating monad transformers (functional pearl). In Proc. of the 10th International Conference on Functional Programming, pages 192--203, 2005.
    [17]
    O. Kiselyov, A. Sabry, and C. Swords. Extensible effects: An alternative to monad transformers. In Proc. of the '13 Symposium on Haskell, pages 59--70, 2013.
    [18]
    S. Liang, P. Hudak, and M. Jones. Monad transformers and modular interpreters. In Proc. of the 22nd Symposium on Principles of Programming Languages, pages 333--343, 1995.
    [19]
    C. Lin. Programming monads operationally with unimo. In Proc. of the 11th International Conference on Functional Programming, pages 274--285, 2006.
    [20]
    C. Okasaki. Simple and efficient purely functional queues and deques. J. of Functional Programming, 5: 583--592, 1995.
    [21]
    C. Okasaki. Purely Functional Data Structures. Cambridge University Press, 1998.
    [22]
    W. Swierstra. Data types à la carte. J. of Functional Programming, 18 (4): 423--436, 2008.
    [23]
    A. van der Ploeg. Monadic functional reactive programming. In Proc. of the '13 Symposium on Haskell, pages 117--128, 2013.
    [24]
    J. Voigtländer. Asymptotic improvement of computations over free monads. In Proc. of the 9th International Conference on Mathematics of Program Construction, pages 388--403, 2008.
    [25]
    P. Wadler. Views: A way for pattern matching to cohabit with data abstraction. In Proc. of the 14th Symposium on Principles of Programming Languages, pages 307--313, 1987.
    [26]
    M. Wand and D. Vaillancourt. Relating models of backtracking. In Proc. of the 9th International Conference on Functional Programming, pages 54--65, 2004.

    Cited By

    View all
    • (2020)Structured Traversal of Search Trees in Constraint-Logic Object-Oriented ProgrammingDeclarative Programming and Knowledge Management10.1007/978-3-030-46714-2_13(199-214)Online publication date: 5-May-2020
    • (2015)Fusion for FreeMathematics of Program Construction10.1007/978-3-319-19797-5_15(302-322)Online publication date: 9-Jun-2015
    • (2021)Efficient compilation of algebraic effect handlersProceedings of the ACM on Programming Languages10.1145/34854795:OOPSLA(1-28)Online publication date: 15-Oct-2021
    • Show More Cited By

    Index Terms

    1. Reflection without remorse: revealing a hidden sequence to speed up monadic reflection

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 49, Issue 12
      Haskell '14
      December 2014
      141 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2775050
      • Editor:
      • Andy Gill
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell '14: Proceedings of the 2014 ACM SIGPLAN symposium on Haskell
        September 2014
        154 pages
        ISBN:9781450330411
        DOI:10.1145/2633357
      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: 03 September 2014
      Published in SIGPLAN Volume 49, Issue 12

      Check for updates

      Author Tags

      1. data structures
      2. monads
      3. performance
      4. reflection

      Qualifiers

      • Research-article

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

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

      Other Metrics

      Citations

      Cited By

      View all
      • (2020)Structured Traversal of Search Trees in Constraint-Logic Object-Oriented ProgrammingDeclarative Programming and Knowledge Management10.1007/978-3-030-46714-2_13(199-214)Online publication date: 5-May-2020
      • (2015)Fusion for FreeMathematics of Program Construction10.1007/978-3-319-19797-5_15(302-322)Online publication date: 9-Jun-2015
      • (2021)Efficient compilation of algebraic effect handlersProceedings of the ACM on Programming Languages10.1145/34854795:OOPSLA(1-28)Online publication date: 15-Oct-2021
      • (2020)Effect handlers, evidentlyProceedings of the ACM on Programming Languages10.1145/34089814:ICFP(1-29)Online publication date: 3-Aug-2020
      • (2019)Monad transformers and modular algebraic effects: what binds them togetherProceedings of the 12th ACM SIGPLAN International Symposium on Haskell10.1145/3331545.3342595(98-113)Online publication date: 8-Aug-2019
      • (2018)A unified view of monadic and applicative non-determinismScience of Computer Programming10.1016/j.scico.2017.09.007152:C(70-98)Online publication date: 15-Jan-2018
      • (2015)Freer monads, more extensible effectsACM SIGPLAN Notices10.1145/2887747.280431950:12(94-105)Online publication date: 30-Aug-2015
      • (2015)Functional pearl: a smart view on datatypesACM SIGPLAN Notices10.1145/2858949.278474350:9(355-361)Online publication date: 29-Aug-2015
      • (2015)Freer monads, more extensible effectsProceedings of the 2015 ACM SIGPLAN Symposium on Haskell10.1145/2804302.2804319(94-105)Online publication date: 30-Aug-2015
      • (2015)From monoids to near-semiringsProceedings of the 17th International Symposium on Principles and Practice of Declarative Programming10.1145/2790449.2790514(196-207)Online publication date: 14-Jul-2015
      • 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