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.
- S. Awodey. Category theory. Oxford University Press, 2006.Google Scholar
- M. Blažević. Coroutine pipelines. The Monad Reader, 19: 29--50, 2011.Google Scholar
- J. Cheney and R. Hinze. First-class phantom types. Technical report, Cornell University, 2003.Google Scholar
- K. Claessen. Functional pearl: Parallel parsing processes. J. of Functional Programming, 14: 741--757, 2004. Google ScholarDigital Library
- 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 ScholarDigital Library
- A. Filinski. Representing monads. In Proc. of the 21th Symposium on Principles of Programming Languages, pages 446--457, 1994. Google ScholarDigital Library
- 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 Scholar
- R. Hinze. Deriving backtracking monad transformers. In Proc. of the 5th International Conference on Functional Programming, pages 186--197, 2000. Google ScholarDigital Library
- R. Hinze and R. Paterson. Finger trees: A simple general-purpose data structure. J. Funct. Program., 16 (2): 197--217, 2006. Google ScholarDigital Library
- J. Hughes. A novel representation of lists and its application to the function 'reverse'. Information Processing Letters, 22 (3): 141--144, 1986. Google ScholarDigital Library
- M. Jaskelioff. Modular monad transformers. In Transactions on Programming Languages and Systems, pages 64--79, 2009. Google ScholarDigital Library
- M. P. Jones and L. Duponcheel. Composing monads. Research Report YALEU/DCS/RR-1004, Yale University, 1993.Google Scholar
- O. Kammar, S. Lindley, and N. Oury. Handlers in action. In Proc. of the 18th International Conference on Functional Programming, 2013. Google ScholarDigital Library
- H. Kaplan and R. E. Tarjan. Purely functional, real-time deques with catenation. J. of the ACM, 46 (5): 577--603, 1999. Google ScholarDigital Library
- O. Kiselyov. Iteratees. In Proc. of the 11th International Symposium on Functional and Logic Programming, pages 166--181, 2012. Google ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- C. Lin. Programming monads operationally with unimo. In Proc. of the 11th International Conference on Functional Programming, pages 274--285, 2006. Google ScholarDigital Library
- C. Okasaki. Simple and efficient purely functional queues and deques. J. of Functional Programming, 5: 583--592, 1995.Google ScholarCross Ref
- C. Okasaki. Purely Functional Data Structures. Cambridge University Press, 1998. Google ScholarDigital Library
- W. Swierstra. Data types à la carte. J. of Functional Programming, 18 (4): 423--436, 2008. Google ScholarDigital Library
- A. van der Ploeg. Monadic functional reactive programming. In Proc. of the '13 Symposium on Haskell, pages 117--128, 2013. Google ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- M. Wand and D. Vaillancourt. Relating models of backtracking. In Proc. of the 9th International Conference on Functional Programming, pages 54--65, 2004. Google ScholarDigital Library
Index Terms
- Reflection without remorse: revealing a hidden sequence to speed up monadic reflection
Recommendations
Reflection without remorse: revealing a hidden sequence to speed up monadic reflection
Haskell '14A 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 ...
Coproducts of Monads on Set
LICS '12: Proceedings of the 2012 27th Annual IEEE/ACM Symposium on Logic in Computer ScienceCoproducts of monads on $\Set$ have arisen in both the study of computational effects and universal algebra. We describe coproducts of consistent monads on $\Set$ by an initial algebra formula, and prove also the converse: if the coproduct exists, so do ...
Idioms are Oblivious, Arrows are Meticulous, Monads are Promiscuous
We revisit the connection between three notions of computation: Moggi s monads, Hughes s arrows and McBride and Paterson s idioms (also called applicative functors). We show that idioms are equivalent to arrows that satisfy the type isomorphism A B 1 (A ...
Comments