Abstract
Left-nested list concatenations, left-nested binds on the free monad, and left-nested choices in many non-determinism monads have an algorithmically bad performance. Can we solve this problem without losing the ability to pattern-match on the computation? Surprisingly, there is a deceptively simple solution: use a smart view to pattern-match on the datatype. We introduce the notion of smart view and show how it solves the problem of slow left-nested operations. In particular, we use the technique to obtain fast and simple implementations of lists, of free monads, and of two non-determinism monads.
- H. Apfelmus. The Operational Monad Tutorial. The Monad.Reader, Issue 15, January 2010.Google Scholar
- R. Hinze. Deriving backtracking monad transformers. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming, ICFP ’00, pages 186–197, New York, NY, USA, 2000. Google Scholar
Digital Library
- ACM. ISBN 1-58113-202-6.Google Scholar
- R. Hinze and R. Paterson. Finger trees: a simple general-purpose data structure. J. Funct. Program., 16(2):197–217, 2006. Google Scholar
Digital Library
- J. Hughes. A novel representation of lists and its application to the function “reverse”. Information Processing Letters, 22(3):141–144, 1986. Google Scholar
Digital Library
- G. Hutton, M. Jaskelioff, and A. Gill. Factorising folds for faster functions. Journal of Functional Programming, 20(Special Issue 3-4): 353–373, 2010. Google Scholar
Digital Library
- M. Jaskelioff and E. Moggi. Monad transformers as monoid transformers. Theoretical Computer Science, 411(51-52):4441 – 4466, 2010. Google Scholar
Digital Library
- O. Kiselyov, C. Shan, D. P. Friedman, and A. Sabry. Backtracking, interleaving, and terminating monad transformers: (functional pearl). In O. Danvy and B. C. Pierce, editors, Proceedings of the 10th ACM SIGPLAN International Conference on Functional Programming, ICFP 2005, Tallinn, Estonia, September 26-28, 2005, pages 192–203. ACM, 2005. ISBN 1-59593-064-7. Google Scholar
Digital Library
- C. Okasaki. Views for Standard ML. In SIGPLAN Workshop on ML, pages 14–23, 1998.Google Scholar
- C. Okasaki. Purely Functional Data Structures. Cambridge University Press, New York, NY, USA, 1998. ISBN 0-521-63124-6. Google Scholar
Cross Ref
- E. Rivas and M. Jaskelioff. Notions of computation as monoids. CoRR, abs/1406.4823, 2014. URL http://arxiv.org/abs/1406.4823.Google Scholar
- Submitted to the Journal of Functional Programming.Google Scholar
- M. R. Sleep and S. Holmström. A short note concerning lazy reduction rules for append. Software: Practice and Experience, 12(11):1082– 1084, 1982. ISSN 1097-024X.Google Scholar
Cross Ref
- T. Uustalu. Explicit binds: Effortless efficiency with and without trees. In T. Schrijvers and P. Thiemann, editors, Functional and Logic Programming - 11th International Symposium, FLOPS 2012, Kobe, Japan, May 23-25, volume 7294 of Lecture Notes in Computer Science, pages 317–331. Springer, 2012. ISBN 978-3-642-29821-9. Google Scholar
Digital Library
- A. van der Ploeg and O. Kiselyov. Reflection without remorse: revealing a hidden sequence to speed up monadic reflection. In W. Swierstra, editor, Proceedings of the 2014 ACM SIGPLAN symposium on Haskell, Gothenburg, Sweden, September 4-5, 2014, pages 133–144. ACM, 2014. ISBN 978-1-4503-3041-1. Google Scholar
Digital Library
- J. Voigtländer. Concatenate, reverse and map vanish for free. SIGPLAN Not., 37(9):14–25, Sept. 2002. ISSN 0362-1340. Google Scholar
Digital Library
- J. Voigtländer. Asymptotic improvement of computations over free monads. In Proceedings of the 9th International Conference on Mathematics of Program Construction, MPC ’08, pages 388–403, Berlin, Heidelberg, 2008. Springer-Verlag. ISBN 978-3-540-70593-2. Google Scholar
Digital Library
- P. Wadler. The concatenate vanishes. Technical report, Department of Computer Science, Glasgow University, December 1987.Google Scholar
Index Terms
Functional pearl: a smart view on datatypes
Recommendations
Functional pearl: a smart view on datatypes
ICFP 2015: Proceedings of the 20th ACM SIGPLAN International Conference on Functional ProgrammingLeft-nested list concatenations, left-nested binds on the free monad, and left-nested choices in many non-determinism monads have an algorithmically bad performance. Can we solve this problem without losing the ability to pattern-match on the ...
From monoids to near-semirings: the essence of MonadPlus and alternative
PPDP '15: Proceedings of the 17th International Symposium on Principles and Practice of Declarative ProgrammingIt is well-known that monads are monoids in the category of endofunctors, and in fact so are applicative functors. Unfortunately, the benefits of this unified view are lost when the additional nondeterminism structure of MonadPlus or Alternative is ...
A non-commutative and non-idempotent theory of quantale sets
In fuzzy set theory non-idempotency arises when the conjunction is interpreted by arbitrary t-norms. There are many instances in mathematics where set theory ought to be non-commutative and/or non-idempotent. The purpose of this paper is to combine both ...






Comments