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

Functional pearl: a smart view on datatypes

Published: 29 August 2015 Publication History

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.
[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.
[3]
ACM. ISBN 1-58113-202-6.
[4]
R. Hinze and R. Paterson. Finger trees: a simple general-purpose data structure. J. Funct. Program., 16(2):197–217, 2006.
[5]
J. Hughes. A novel representation of lists and its application to the function “reverse”. Information Processing Letters, 22(3):141–144, 1986.
[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.
[7]
M. Jaskelioff and E. Moggi. Monad transformers as monoid transformers. Theoretical Computer Science, 411(51-52):4441 – 4466, 2010.
[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.
[9]
C. Okasaki. Views for Standard ML. In SIGPLAN Workshop on ML, pages 14–23, 1998.
[10]
C. Okasaki. Purely Functional Data Structures. Cambridge University Press, New York, NY, USA, 1998. ISBN 0-521-63124-6.
[11]
E. Rivas and M. Jaskelioff. Notions of computation as monoids. CoRR, abs/1406.4823, 2014. URL http://arxiv.org/abs/1406.4823.
[12]
Submitted to the Journal of Functional Programming.
[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.
[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.
[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.
[16]
J. Voigtländer. Concatenate, reverse and map vanish for free. SIGPLAN Not., 37(9):14–25, Sept. 2002. ISSN 0362-1340.
[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.
[18]
P. Wadler. The concatenate vanishes. Technical report, Department of Computer Science, Glasgow University, December 1987.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

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

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 29 August 2015

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Data Structure
  2. List
  3. Monad
  4. MonadPlus

Qualifiers

  • Research-article

Funding Sources

Conference

ICFP'15
Sponsor:

Acceptance Rates

Overall Acceptance Rate 333 of 1,064 submissions, 31%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)6
  • Downloads (Last 6 weeks)0
Reflects downloads up to 13 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2021)Algebras for weighted searchProceedings of the ACM on Programming Languages10.1145/34735775:ICFP(1-30)Online publication date: 19-Aug-2021
  • (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
  • (2016)Pattern synonymsACM SIGPLAN Notices10.1145/3241625.297601351:12(80-91)Online publication date: 8-Sep-2016
  • (2016)Pattern synonymsProceedings of the 9th International Symposium on Haskell10.1145/2976002.2976013(80-91)Online publication date: 8-Sep-2016
  • (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
  • (2021)Algebras for weighted searchProceedings of the ACM on Programming Languages10.1145/34735775:ICFP(1-30)Online publication date: 22-Aug-2021

View Options

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