skip to main content
research-article

Functional pearl: a smart view on datatypes

Authors Info & Claims
Published:29 August 2015Publication History
Skip Abstract Section

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.

References

  1. H. Apfelmus. The Operational Monad Tutorial. The Monad.Reader, Issue 15, January 2010.Google ScholarGoogle Scholar
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. ACM. ISBN 1-58113-202-6.Google ScholarGoogle Scholar
  4. 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
  5. 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
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. M. Jaskelioff and E. Moggi. Monad transformers as monoid transformers. Theoretical Computer Science, 411(51-52):4441 – 4466, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. C. Okasaki. Views for Standard ML. In SIGPLAN Workshop on ML, pages 14–23, 1998.Google ScholarGoogle Scholar
  10. C. Okasaki. Purely Functional Data Structures. Cambridge University Press, New York, NY, USA, 1998. ISBN 0-521-63124-6. Google ScholarGoogle ScholarCross RefCross Ref
  11. E. Rivas and M. Jaskelioff. Notions of computation as monoids. CoRR, abs/1406.4823, 2014. URL http://arxiv.org/abs/1406.4823.Google ScholarGoogle Scholar
  12. Submitted to the Journal of Functional Programming.Google ScholarGoogle Scholar
  13. 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 ScholarGoogle ScholarCross RefCross Ref
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. J. Voigtländer. Concatenate, reverse and map vanish for free. SIGPLAN Not., 37(9):14–25, Sept. 2002. ISSN 0362-1340. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. P. Wadler. The concatenate vanishes. Technical report, Department of Computer Science, Glasgow University, December 1987.Google ScholarGoogle Scholar

Index Terms

  1. Functional pearl: a smart view on datatypes

              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

              Full Access

              • Published in

                cover image ACM SIGPLAN Notices
                ACM SIGPLAN Notices  Volume 50, Issue 9
                ICFP '15
                September 2015
                436 pages
                ISSN:0362-1340
                EISSN:1558-1160
                DOI:10.1145/2858949
                • Editor:
                • Andy Gill
                Issue’s Table of Contents
                • cover image ACM Conferences
                  ICFP 2015: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming
                  August 2015
                  436 pages
                  ISBN:9781450336697
                  DOI:10.1145/2784731

                Copyright © 2015 ACM

                Publisher

                Association for Computing Machinery

                New York, NY, United States

                Publication History

                • Published: 29 August 2015

                Check for updates

                Qualifiers

                • research-article

              PDF Format

              View or Download as a PDF file.

              PDF

              eReader

              View online with eReader.

              eReader
              About Cookies On This Site

              We use cookies to ensure that we give you the best experience on our website.

              Learn more

              Got it!