Summary
This chapter is an exploration of the possibilities that open up if we consistently adopt a style of database query and collection processing which allows us to look inside collections and thus enables us to play with atomic constructors instead of the monolithic collection values they build.
This comprehension of values goes well together with a completely functional style of query formulation: queries map between the constructors of different collection types. It turns out that a single uniform type of mapping, the catamorphism, is sufficient to embrace the functionality of today’s database query languages, like SQL, OQL, but also XPath. Monad comprehensions provide just the right amount of syntactic sugar to express these mappings in a style that is similar to relational calculus (but goes beyond its expressiveness).
The major portion of this chapter, however, demonstrates how monad comprehensions enable a succinct yet deep understanding of database queries. We will revisit a number of problems in the advanced query processing domain to see how monad comprehensions can (a) provide remarkably concise proofs of correctness for earlier work, (b) clarify and then broaden the applicability of existing query optimisation techniques, and (c) enable query transformations which otherwise require extensive sets of rewriting rules.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Anders Berglund, Scott Boag, Don Chamberlin, Mary F. Fernandez, Michael Kay, Jonathan Robie, and Jérôme Simeon. XML Path Language (XPath) 2.0. Technical Report W3C Working Draft, Version 2.0, World Wide Web Consortium, December 2001. http://www.w3.org/TR/xpath20/.
Val Breazu-Tannen, Peter Buneman, and Limsoon Wong. Naturally Embedded Query Languages. In Proc. of the International Conference on Database Theory (ICDT), pages 140–154, Berlin, Germany, October 1992.
Peter Buneman, Leonid Libkin, Dan Suciu, Val Tannen, and Limsoon Wong. Comprehension Syntax. ACM SIGMOD Record, 23:87–96, March 1994.
Rick G. Cattell and Douglas K. Barry, editors. The Object Database Standard: ODMG 2.0. Morgan Kaufmann, 1997.
Damianos Chatziantoniou and Kenneth A. Ross. Groupwise Processing of Relational Queries. In Proceedings of the 23rd Internatinal Conference on Very Large Data Bases (VLDB), pages 476–485, Athens, Greece, August 1997.
Peter Fankhauser and Philip Wadler. XQuery Tutorial. XML2001, Orlando, Florida, USA, December 2001.
Leonidas Fegaras and David Maier. Optimizing Object Queries Using an Effective Calculus. ACM Transactions on Database Systems, 25(4):457–516. 2000.
Richard A. Ganski and Harry K. T. Wong. Optimization of Nested SQL Queries Revisited. In Proceedings of the ACM SIGMOD International Conference on Management of Data, pages 23–33, San Francisco, USA, 1987.
Andrew J. Gill, John Launchbury, and Simon L. Peyton Jones. A Short Cut to Deforestation. In Proceedings of the ACM Conference on Functional Programming and Computer Architecture (FPCA), pages 223–232, Copenhagen, Denmark, April 1993.
Torsten Grust. Comprehending Queries. PhD thesis, University of Konstanz, September 1999. Available at http://www.ub.uni-konstanz.de/kops/volltexte/1999/312/312_l.pdf.
Torsten Grust. Accelerating XPath Location Steps. In Proceedings of the 21st International ACM SIGMOD Conference on Management of Data, pages 109–120, Madison, Wisconsin, USA, June 2002.
Torsten Grust and Marc H. Scholl. How to Comprehend Queries Functionally. Journal of Intelligent Information Systems, 12(2/3): 191–218, March 1999. Special Issue on Functional Approach to Intelligent Information Systems.
Jonathan M.D. Hill. Data-Parallel Lazy Functional Programming. PhD thesis, University of London, Queen Mary and Westfield College, September 1994.
John Hughes and Simon L. Peyton Jones (editors). Haskell 98: A Non-strict, Purely Functional Language, http://haskell.org/definition/, February 1999.
Won Kim. On Optimizing an SQL-like Nested Query. ACM Transactions on Database Systems, 7(3):443–469, September 1982.
Joachim Lambek. A Fixpoint Theorem for Complete Categories. Mathematische Zeitschrift, 103:151–161, 1968.
Erik Meijer, Marten M. Fokkinga, and Ross Paterson. Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. In Procedings of the ACM Conference on Functional Programming and Computer Architecture (FPCA), number 523 in Lecture Notes in Computer Science (LNCS), pages 124–144, Cambridge, USA, 1991. Springer Verlag.
Dan Olteanu, Holger Meuss, Tim Furche, and François Bry. Symmetry in XPath. Technical Report PMS-FB-2001–16, Institute of Computer Science, University of Munich, Germany, October 2001.
Simon Peyton-Jones. Tackling the Awkward Squad: Monadic Input/Output, Concurrency, Exceptions, and Foreign-Language Calls in Haskell. In Tony Hoare, Manfred Broy, and Ralf Steinbruggen, editors, Engineering Theories of Software Construction, pages 47–96. IOS Press, 2001.
Hennie J. Steenhagen, Peter M.G. Apers, and Henk M. Blanken. Optimization of Nested Queries in a Complex Object Model. In Proceedings of the 4th Interntional Conference on Extending Database Technology (EDBT), pages 337–350, Cambridge, UK, March 1994.
Dan Suciu and Limsoon Wong. On Two Forms of Strutural Recursion. In Georg Gottlob and Moshe Y. Vardi, editors, Proceedings of the 5th International Conference on Database Theory (ICDT), number 893 in Lecture Notes in Computer Science (LNCS), pages 111–124, Prague, Czech Republic, January 1995. Springer Verlag.
Akihiko Takano and Erik Meijer. Shortcut Deforestation in Calculational Form. In Proceedings of the ACM Conference on Functional Programming and Computer Architecture (FPCA), pages 306–313, La Jolla, USA, June 1995. ACM Press.
Philip Wadler. Theorems for Free! In Proceedings of the 4th International Conference on Functional Programming and Computer Architecture (FPCA), London, England, September 1989.
Philip Wadler. Comprehending Monads. In Conference on Lisp and Functional Programming, pages 61–78, June 1990.
Limsoon Wong. Querying Nested Collections. PhD thesis, University of Pennsylvania, Philadelphia, August 1994.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2004 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Grust, T. (2004). Monad Comprehensions: A Versatile Representation for Queries. In: Gray, P.M.D., Kerschberg, L., King, P.J.H., Poulovassilis, A. (eds) The Functional Approach to Data Management. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-662-05372-0_12
Download citation
DOI: https://doi.org/10.1007/978-3-662-05372-0_12
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-05575-1
Online ISBN: 978-3-662-05372-0
eBook Packages: Springer Book Archive