skip to main content
10.1145/2633357.2633360acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

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

Published:03 September 2014Publication History

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.Google ScholarGoogle Scholar
  2. M. Blažević. Coroutine pipelines. The Monad Reader, 19: 29--50, 2011.Google ScholarGoogle Scholar
  3. J. Cheney and R. Hinze. First-class phantom types. Technical report, Cornell University, 2003.Google ScholarGoogle Scholar
  4. K. Claessen. Functional pearl: Parallel parsing processes. J. of Functional Programming, 14: 741--757, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. A. Filinski. Representing monads. In Proc. of the 21th Symposium on Principles of Programming Languages, pages 446--457, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  8. R. Hinze. Deriving backtracking monad transformers. In Proc. of the 5th International Conference on Functional Programming, pages 186--197, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. Hinze and R. Paterson. Finger trees: A simple general-purpose data structure. J. Funct. Program., 16 (2): 197--217, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Hughes. A novel representation of lists and its application to the function 'reverse'. Information Processing Letters, 22 (3): 141--144, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. M. Jaskelioff. Modular monad transformers. In Transactions on Programming Languages and Systems, pages 64--79, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. M. P. Jones and L. Duponcheel. Composing monads. Research Report YALEU/DCS/RR-1004, Yale University, 1993.Google ScholarGoogle Scholar
  13. O. Kammar, S. Lindley, and N. Oury. Handlers in action. In Proc. of the 18th International Conference on Functional Programming, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. H. Kaplan and R. E. Tarjan. Purely functional, real-time deques with catenation. J. of the ACM, 46 (5): 577--603, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. O. Kiselyov. Iteratees. In Proc. of the 11th International Symposium on Functional and Logic Programming, pages 166--181, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. C. Lin. Programming monads operationally with unimo. In Proc. of the 11th International Conference on Functional Programming, pages 274--285, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. C. Okasaki. Simple and efficient purely functional queues and deques. J. of Functional Programming, 5: 583--592, 1995.Google ScholarGoogle ScholarCross RefCross Ref
  21. C. Okasaki. Purely Functional Data Structures. Cambridge University Press, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. W. Swierstra. Data types à la carte. J. of Functional Programming, 18 (4): 423--436, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. A. van der Ploeg. Monadic functional reactive programming. In Proc. of the '13 Symposium on Haskell, pages 117--128, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. M. Wand and D. Vaillancourt. Relating models of backtracking. In Proc. of the 9th International Conference on Functional Programming, pages 54--65, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

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

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in
    • Published in

      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
      • 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

      Copyright © 2014 ACM

      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: 3 September 2014

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article

      Acceptance Rates

      Haskell '14 Paper Acceptance Rate12of28submissions,43%Overall Acceptance Rate57of143submissions,40%

      Upcoming Conference

      ICFP '24

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader