Skip to main content

Monad Comprehensions: A Versatile Representation for Queries

  • Chapter
The Functional Approach to Data Management

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 129.00
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 169.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 169.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 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/.

  2. 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.

    Google Scholar 

  3. Peter Buneman, Leonid Libkin, Dan Suciu, Val Tannen, and Limsoon Wong. Comprehension Syntax. ACM SIGMOD Record, 23:87–96, March 1994.

    Article  Google Scholar 

  4. Rick G. Cattell and Douglas K. Barry, editors. The Object Database Standard: ODMG 2.0. Morgan Kaufmann, 1997.

    MATH  Google Scholar 

  5. 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.

    Google Scholar 

  6. Peter Fankhauser and Philip Wadler. XQuery Tutorial. XML2001, Orlando, Florida, USA, December 2001.

    Google Scholar 

  7. Leonidas Fegaras and David Maier. Optimizing Object Queries Using an Effective Calculus. ACM Transactions on Database Systems, 25(4):457–516. 2000.

    Article  MATH  Google Scholar 

  8. 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.

    Google Scholar 

  9. 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.

    Chapter  Google Scholar 

  10. 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.

    Google Scholar 

  11. 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.

    Google Scholar 

  12. 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.

    Article  Google Scholar 

  13. Jonathan M.D. Hill. Data-Parallel Lazy Functional Programming. PhD thesis, University of London, Queen Mary and Westfield College, September 1994.

    Google Scholar 

  14. John Hughes and Simon L. Peyton Jones (editors). Haskell 98: A Non-strict, Purely Functional Language, http://haskell.org/definition/, February 1999.

    Google Scholar 

  15. Won Kim. On Optimizing an SQL-like Nested Query. ACM Transactions on Database Systems, 7(3):443–469, September 1982.

    Article  MATH  Google Scholar 

  16. Joachim Lambek. A Fixpoint Theorem for Complete Categories. Mathematische Zeitschrift, 103:151–161, 1968.

    Article  MathSciNet  MATH  Google Scholar 

  17. 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.

    Chapter  Google Scholar 

  18. 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.

    Google Scholar 

  19. 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.

    Google Scholar 

  20. 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.

    Google Scholar 

  21. 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.

    Google Scholar 

  22. 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.

    Google Scholar 

  23. Philip Wadler. Theorems for Free! In Proceedings of the 4th International Conference on Functional Programming and Computer Architecture (FPCA), London, England, September 1989.

    Google Scholar 

  24. Philip Wadler. Comprehending Monads. In Conference on Lisp and Functional Programming, pages 61–78, June 1990.

    Google Scholar 

  25. Limsoon Wong. Querying Nested Collections. PhD thesis, University of Pennsylvania, Philadelphia, August 1994.

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics