skip to main content
research-article

Haskell, do you read me?: constructing and composing efficient top-down parsers at runtime

Published:25 September 2008Publication History
Skip Abstract Section

Abstract

The Haskell definition and implementation of read is far from perfect. In the first place read is not able to handle the associativities defined for infix operators. Furthermore, it puts constraints on the way show is defined, and especially forces it to generate far more parentheses than expected. Lastly, it may give rise to exponential parsing times. All this is due to the compositionality requirement for read functions, which imposes a top-down parsing strategy.

We propose a different approach, based on typed abstract syntax, in which grammars describing the data types are composed dynamically. Using the transformation libraries described in a companion paper these syntax descriptions are combined and transformed into parsers at runtime, from which the required read function are constructed. In this way we obtain linear parsing times, achieve consistency with the defined associativities, and may use a version of show which generates far fewer parentheses, thus improving readability of printed values.

The described transformation algorithms can be incorporated in a Haskell compiler, thus moving most of the work involved to compile time.

Skip Supplemental Material Section

Supplemental Material

Video

References

  1. Arthur Baars and Doaitse Swierstra. Typed transformations of typed abstract syntax. http://www.cs.uu.nl/research/techreps/, Utrecht University, 2008.Google ScholarGoogle Scholar
  2. Arthur Baars, Andres Löh, and Doaitse Swierstra. Parsing permutation phrases. J. Funct. Program., 14 (6): 635--646, 2004. ISSN 0956-7968. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Arthur I. Baars and S. Doaitse Swierstra. Type-safe, self inspecting code. In Haskell '04: Proceedings of the 2004 ACM SIGPLAN workshop on Haskell, pages 69--79, New York, NY, USA, 2004. ACM. ISBN 1-58113-850-4. http://doi.acm.org/10.1145/1017472.1017485. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Eric Bouwers, Martin Bravenboer, and Eelco Visser. Grammar engineering support for precedence rule recovery and compatibility checking. Electron. Notes Theor. Comput. Sci., 203 (2): 85--101, 2008. ISSN 1571-0661. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Martin Bravenboer. Exercises in Free Syntax. Syntax Definition, Parsing, and Assimilation of Language Conglomerates. PhD thesis, Utrecht University, Utrecht, The Netherlands, January 2008.Google ScholarGoogle Scholar
  6. M. Johnson. Finite-state approximation of constraint-based grammars using left-corner grammar transforms. In COLING-ACL '98, Montreal, Quebec, Canada, pages 619--623. Association for Computational Linguistics, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate: a practical design pattern for generic programming. ACM SIGPLAN Notices, 38 (3): 26--37, March 2003. Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003). Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Ralf Lämmel and Simon Peyton Jones. Scrap more boilerplate: reflection, zips, and generalised casts. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2004), pages 244--255. ACM Press, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18 (01): 1--13, 2007. 10.1017/S0956796807006326. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Emir Pasalic and Nathan Linger. Meta-programming with typed object-language representations. In Generative Programming and Component Engineering (GPCE'04), volume LNCS 3286, pages 136--167, October 2004.Google ScholarGoogle Scholar
  11. JC Petruzza, Koen Claessen, and Simon Peyton Jones. Derived read instances for recursive datatypes with infix constructors are too inefficient. URL http://hackage.haskell.org/trac/ghc/ticket/1544. GHC Ticket 1544.Google ScholarGoogle Scholar
  12. Simon Peyton Jones. Haskell 98 Language and Libraries: the Revised Report. 2003.Google ScholarGoogle Scholar
  13. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. Simple nification-based type inference for gadts. SIGPLAN Not., 41 (9): 50--61, 2006. ISSN 0362--1340. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Tim Sheard and Simon Peyton Jones. Template meta-programming for haskell. In Proceedings of the ACM SIGPLAN workshop on Haskell, pages 1--16. ACM Press, 2002. ISBN 1-58113-605-6. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. S. D. Swierstra. The Utrecht Parsing Libraries. http://www.cs.uu.nl/wiki/bin/view/HUT/ParserCombinators, July 2008.Google ScholarGoogle Scholar

Index Terms

  1. Haskell, do you read me?: constructing and composing efficient top-down parsers at runtime

      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

      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!