skip to main content
article
Open access

Pretty printing with lazy dequeues

Published: 01 January 2005 Publication History

Abstract

There are several purely functional libraries for converting tree structured data into indented text, but they all make use of some backtracking. Over twenty years ago, Oppen published a more efficient imperative implementation of a pretty printer. This article shows that the same efficiency is also obtainable without destructive updates by developing a similar but purely functional Haskell implementation with the same complexity bounds. At its heart lie two lazy double ended queues.

References

[1]
Azero, P. and Swierstra, D. 1998. Optimal pretty-printing combinators. http://www.cs.uu.nl/groups/ST/Center/SoftwareDistributions.
[2]
Bird, R. S. 1984. Using circular programs to eliminate multiple traversals of data. Acta Inf. 21, 239--250.
[3]
Hughes, J. 1986. A novel representation of lists and its application to the function “reverse”. Inf. Proc. Lett. 22, 3, 141---144.
[4]
Hughes, J. 1995. The design of a pretty-printing library. In Advanced Functional Programming, J. Jeuring and E. Meijer, Eds. Lecture Notes in Computer Science, vol. 925. Springer-Verlag, New York.
[5]
Okasaki, C. 1998. Purely Functional Data Structures. Cambridge University Press.
[6]
Okasaki, C. 2000. Breadth-first numbering: Lessons from a small exercise in algorithm design. In Proceedings of the International Conference on Functional Programming. 131--136.
[7]
Oppen, D. C. 1980. Prettyprinting. ACM Trans. Prog. Lang. Syst. 2, 4, 465--483.
[8]
Peyton Jones, S. L. 1997. A pretty printer library in Haskell. Part of the GHC distribution at http://www.haskell.org/ghc.
[9]
Peyton Jones, S. L., Ed. 2003. Haskell 98 Language and Libraries, The Revised Report. Cambridge University Press.
[10]
Wadler, P. 2003. A prettier printer. In The Fun of Programming. Palgrave Macmillan, Chapter 11, 223--244.

Cited By

View all
  • (2023)A Pretty Expressive PrinterProceedings of the ACM on Programming Languages10.1145/36228377:OOPSLA2(1122-1149)Online publication date: 16-Oct-2023
  • (2016)Towards a universal code formatter through machine learningProceedings of the 2016 ACM SIGPLAN International Conference on Software Language Engineering10.1145/2997364.2997383(137-151)Online publication date: 20-Oct-2016
  • (2016)Proceedings of the 2016 ACM SIGPLAN International Conference on Software Language EngineeringundefinedOnline publication date: 20-Oct-2016
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 27, Issue 1
January 2005
184 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/1053468
Issue’s Table of Contents

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 01 January 2005
Published in TOPLAS Volume 27, Issue 1

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Haskell
  2. lazy functional programming

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)62
  • Downloads (Last 6 weeks)3
Reflects downloads up to 24 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2023)A Pretty Expressive PrinterProceedings of the ACM on Programming Languages10.1145/36228377:OOPSLA2(1122-1149)Online publication date: 16-Oct-2023
  • (2016)Towards a universal code formatter through machine learningProceedings of the 2016 ACM SIGPLAN International Conference on Software Language Engineering10.1145/2997364.2997383(137-151)Online publication date: 20-Oct-2016
  • (2016)Proceedings of the 2016 ACM SIGPLAN International Conference on Software Language EngineeringundefinedOnline publication date: 20-Oct-2016
  • (2015)Polynomial-Time Optimal Pretty-Printing Combinators with ChoicePerspectives of System Informatics10.1007/978-3-662-46823-4_21(257-265)Online publication date: 19-Apr-2015
  • (2013)A Pretty Good Formatting PipelineSoftware Language Engineering10.1007/978-3-319-02654-1_10(177-196)Online publication date: 2013
  • (2012)Lazy v. Yield: Incremental, Linear Pretty-PrintingProgramming Languages and Systems10.1007/978-3-642-35182-2_14(190-206)Online publication date: 2012
  • (2009)Linear, bounded, functional pretty-printingJournal of Functional Programming10.1017/S095679680800699019:1(1-16)Online publication date: 1-Jan-2009
  • (2005)Haskell ready to dazzle the real worldProceedings of the 2005 ACM SIGPLAN workshop on Haskell10.1145/1088348.1088351(17-26)Online publication date: 30-Sep-2005
  • (2004)Type-safe, self inspecting codeProceedings of the 2004 ACM SIGPLAN workshop on Haskell10.1145/1017472.1017485(69-79)Online publication date: 22-Sep-2004

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media