Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
Total parser combinators
Danielsson N. ACM SIGPLAN Notices45 (9):285-296,2010.Type:Article
Date Reviewed: Oct 13 2011

Parser combinators are one of the best-known examples of the advantages of functional programming, as they make essential use of functions as arguments and results of functions. They are also one of the longest standing examples, going back to Burge’s groundbreaking 1975 work [1]. In this model, parsers are represented as functions, which partially consume input streams and return parse trees. Parser combinators directly represent grammar operations like alternation, repetition, and sequencing; complex parsers are built by applying these combinators to simpler ones, generally in a recursive definition. With recursion comes the possibility--indeed probability--of nontermination.

Dependent types have come into functional programming from constructive mathematics, particularly from the work of Per Martin-L¿f, which also began in the 1970s. Dependent types are types that depend on values, and this simple mechanism establishes a correspondence between types and logical predicates, and between the values those types contain and proofs of the predicates. Dependent types thus have the power to express constraints far more fine grained than traditional type systems. For the programming-logic correspondence to work properly, the logic needs to be consistent: that is, not everything should be provable. To do this, general recursion needs to be banned, and only terminating forms of recursion and co-recursion can be permitted; this is precisely what the Agda language, in which the work of this paper is implemented, supports.

Terminating recursion is straightforward: progress towards termination can be measured by the arguments shrinking. Co-recursion is less familiar, and is dual to recursion: instead of consuming arguments, co-recursion generates results, and for co-recursion to be acceptable, it needs to be “productive”; that is, co-recursively defined objects, like infinite lists, need to be unfoldable indefinitely.

There are several contributions of this paper. First, it gives an implementation of parser combinators in a total language, in a way that supports left recursion. For this to work, it is essential that certain parsers must not accept the empty string, and this constraint can be expressed in dependent types (it’s a simple predicate, after all). More generally, it gives a tutorial example in combining recursion--for grammatical structure--and co-recursion--for controlled recursive grammar definitions. The author concludes the paper with a persuasive argument that this approach gives a framework for understanding the behavior of lazy programming in languages like Haskell, where recursion and co-recursion overlap.

This well-written paper contains a particularly useful survey of related work right at the start, helping to contextualize the contribution. It should be essential reading for anyone interested in parsing and advances in dependently typed functional programming.

Reviewer:  Simon Thompson Review #: CR139497 (1203-0283)
1) Burge, W.H. Recursive programming techniques. Addison-Wesley, Reading, MA, 1975.
Bookmark and Share
  Featured Reviewer  
 
Applicative (Functional) Programming (D.1.1 )
 
 
Parsing (F.4.2 ... )
 
 
Specifying And Verifying And Reasoning About Programs (F.3.1 )
 
 
Data Structures (E.1 )
 
Would you recommend this review?
yes
no
Other reviews under "Applicative (Functional) Programming": Date
Functional programming with Hope
Bailey R., Ellis Horwood, Upper Saddle River, NJ, 1990. Type: Book (9780133382372)
May 1 1992
Prospects for functional programming in software engineering
Banâtre J., Jones S., Le Métayer D. (ed), Springer-Verlag New York, Inc., New York, NY, 1991. Type: Book (9780387538525)
Aug 1 1992
An introduction to functional programming
Bird R. (ed), Wadler P., Prentice Hall International (UK) Ltd., Hertfordshire, UK, 1988. Type: Book (9780134841892)
May 1 1992
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy