Abstract
Bulk types such as sets, bags, and lists are monads, and therefore support a notation for database queries based on comprehensions. This fact is the basis of much work on database query languages. The monadic structure easily explains most of standard relational algebra---specifically, selections and projections---allowing for an elegant mathematical foundation for those aspects of database query language design. Most, but not all: monads do not immediately offer an explanation of relational join or grouping, and hence important foundations for those crucial aspects of relational algebra are missing. The best they can offer is cartesian product followed by selection. Adjunctions come to the rescue: like any monad, bulk types also arise from certain adjunctions; we show that by paying due attention to other important adjunctions, we can elegantly explain the rest of standard relational algebra. In particular, graded monads provide a mathematical foundation for indexing and grouping, which leads directly to an efficient implementation, even of joins.
Supplemental Material
Available for Download
Supplemental file
- Alexander Alexandrov, Andreas Kunft, Asterios Katsifodimos, Felix Schüler, Lauritz Thamsen, Odej Kao, Tobias Herb, and Volker Markl. 2015. Implicit Parallelism through Deep Language Embedding. In SIGMOD record. ACM, 47–61. Google ScholarDigital Library
- Steve Awodey. 2006. Category Theory. Oxford University Press. Google ScholarDigital Library
- Peter Buneman, Leonid Libkin, Dan Suciu, Val Tannen, and Limsoon Wong. 1994. Comprehension Syntax. SIGMOD Record 23, 1 (1994), 87–96. Google ScholarDigital Library
- Stanley Burris and Simon Lee. 1993. Tarski’s High School Identities. Amer. Math. Monthly 100, 3 (March 1993), 231–236.Google Scholar
- Jacques Carette. 2018. Email correspondence. (May 2018). Personal communication.Google Scholar
- James Cheney, Sam Lindley, and Philip Wadler. 2013. A Practical Theory of Language-Integrated Query. In International Conference on Functional Programming , Greg Morrisett and Tarmo Uustalu (Eds.). ACM, 403–416. Google ScholarDigital Library
- Eugenia Cheng. 2015. Cakes, Custard, and Category Theory. Profile Books.Google Scholar
- Richard H. Connelly and F. Lockwood Morris. 1995. A Generalization of the Trie Data Structure. Mathematical Structures in Computer Science 5, 3 (September 1995), 381–418.Google ScholarCross Ref
- Ezra Cooper, Sam Lindley, Philip Wadler, and Jeremy Yallop. 2006. Links: Web Programming without Tiers. In Formal Methods for Components and Objects (Lecture Notes in Computer Science) , Vol. 4709. Springer, 266–296. Google ScholarDigital Library
- John Darlington. 1975. Application of Program Transformation to Program Synthesis. In IRIA Symposium on Proving and Improving Programs . Arc-et-Senans, France, 133–144.Google Scholar
- Christopher J. Date. 2004. An Introduction to Database Systems (8th ed.). Pearson. Google ScholarDigital Library
- Mary Fernandez, Jerome Simeon, and Philip Wadler. 2001. A Semi-Monad for Semi-Structured Data. In International Conference on Database Theory (Lecture Notes in Computer Science) , Jan Van den Bussche and Victor Vianu (Eds.), Vol. 1973. Springer, 263–300. Google ScholarDigital Library
- Marcelo Fiore, Roberto Di Cosmo, and Vincent Balat. 2006. Remarks on Isomorphisms in Typed Lambda Calculi with Empty and Sum Types. Annals of Pure and Applied Logic 141, 1-2 (2006), 35–50.Google ScholarCross Ref
- Soichiro Fujii, Shin-ya Katsumata, and Paul-André Melliès. 2016. Towards a Formal Theory of Graded Monads. In Foundations of Software Science and Computation Structures (Lecture Notes in Computer Science) . Springer-Verlag, 513–530.Google Scholar
- Jeremy Gibbons. 2016. Comprehending Ringads. In A List of Successes that can Change the World (Lecture Notes in Computer Science) , Sam Lindley, Conor McBride, Don Sannella, and Phil Trinder (Eds.), Vol. 9600. Springer, 132–151.Google Scholar
- George Giorgidze, Torsten Grust, Tom Schreiber, and Jeroen Weijers. 2011a. Haskell Boards the Ferry: Database-Supported Program Execution for Haskell. In Implementation and Application of Functional Languages (Lecture Notes in Computer Science) , Jurriaan Hage and Marco T. Morazán (Eds.), Vol. 6647. Springer, 1–18. Google ScholarDigital Library
- George Giorgidze, Torsten Grust, Nils Schweinsberg, and Jeroen Weijers. 2011b. Bringing Back Monad Comprehensions. In Haskell Symposium . ACM, 13–22. Google ScholarDigital Library
- Glasgow 2015. Glasgow Haskell Compiler Users’ Guide, Version 7.10.1. https://downloads.haskell.org/~ghc/7.10.1/docs/html/ users_guide/index.html .Google Scholar
- Torsten Grust and Marc H. Scholl. 1999. How to Comprehend Queries Functionally. Journal of Intelligent Information Systems 12, 2-3 (1999), 191–218. Google ScholarDigital Library
- Fritz Henglein and Ralf Hinze. 2013. Distributive Sorting and Searching: From Generic Discrimination to Generic Tries. In Asian Symposium on Programming Languages and Systems (Lecture Notes in Computer Science) , Chung-chieh Shan (Ed.), Vol. 8301. Springer, 315–332. Google ScholarDigital Library
- Fritz Henglein and Ken Friis Larsen. 2010. Generic Multiset Programming with Discrimination-Based Joins and Symbolic Cartesian Products. Higher-Order and Symbolic Computation 23, 3 (2010), 337–370. Google ScholarDigital Library
- Ralf Hinze. 2000. Generalizing Generalized Tries. Journal of Functional Programming 10, 4 (2000), 327–351. Google ScholarDigital Library
- Ralf Hinze. 2003. Fun with Phantom Types. In The Fun of Programming, Jeremy Gibbons and Oege de Moor (Eds.). Palgrave Macmillan, 245–262.Google Scholar
- Shin-ya Katsumata. 2014. Parametric Effect Monads and Semantics of Effect Systems. In Principles of Programming Languages. ACM, 633–645. Google ScholarDigital Library
- Leonid Libkin and Limsoon Wong. 1997. Query Languages for Bags and Aggregate Functions. J. Comput. System Sci. 55, 2 (1997), 241–272. Google ScholarDigital Library
- Conor McBride and Ross Paterson. 2008. Functional Pearl: Applicative Programming with Effects. Journal of Functional Programming 18, 1 (2008), 1–13. Google ScholarDigital Library
- Erik Meijer. 2007. Confessions of a Used Programming Language Salesman. In Object-Oriented Programming: Systems, Languages and Applications . ACM, 677–694. Google ScholarDigital Library
- Hung Q. Ngo, Ely Porat, Christopher Ré, and Atri Rudra. 2012. Worst-Case Optimal Join Algorithms. In Principles of Database Systems . ACM, 37–48. Google ScholarDigital Library
- Dominic A. Orchard, Tomas Petricek, and Alan Mycroft. 2014. The Semantic Marriage of Monads and Effects. CoRR abs/1401.5391 (2014).Google Scholar
- Simon Peyton Jones and Philip Wadler. 2007. Comprehensive Comprehensions. In Haskell Workshop. ACM, 61–72. Google ScholarDigital Library
- Benjamin C. Pierce. 1991. Basic Category Theory for Computer Scientists. MIT Press. Google ScholarDigital Library
- Rinus Plasmeijer and Marko van Eekelen. 1995. Concurrent Clean Language Report (Version 1.0). Technical Report. University of Nijmegen. ftp://ftp.science.ru.nl/pub/Clean/old/Clean10/doc/refman.ps.gz .Google Scholar
- Jacob T. Schwartz, Robert B. K. Dewar, Ed Dubinsky, and Edmond Schonberg. 1986. Programming with Sets: An Introduction to SETL . Springer, New York. Google ScholarDigital Library
- Patricia Griffiths Selinger, Morton M. Astrahan, Donald D. Chamberlin, Raymond A. Lorie, and Thomas G. Price. 1979. Access Path Selection in a Relational Database Management System. In SIGMOD record. ACM, 23–34. Google ScholarDigital Library
- Ross Street. 1972. Two Constructions on Lax Functors. Cahiers de Topologie et Géométrie Différentielle Catégoriques 13, 3 (1972), 217–264. http://eudml.org/doc/91107Google Scholar
- Kenichi Suzuki, Oleg Kiselyov, and Yukiyoshi Kameyama. 2016. Finally, Safely-Extensible and Efficient Language-Integrated Query. In Partial Evaluation and Program Manipulation, Martin Erwig and Tiark Rompf (Eds.). ACM, 37–48. Google ScholarDigital Library
- Don Syme. 2006. Leveraging .NET Meta-programming Components from F#: Integrated Queries and Interoperable Heterogeneous Execution. In ML Workshop. ACM, New York, NY, USA, 43–54. Google ScholarDigital Library
- Philip W. Trinder. 1991. Comprehensions, a Query Notation for DBPLs. In Database Programming Languages. 55–68. Google ScholarDigital Library
- Philip Wadler. 1992. Comprehending Monads. Mathematical Structures in Computer Science 2, 4 (1992), 461–493.Google ScholarCross Ref
- Limsoon Wong. 2000. Kleisli, a Functional Query System. Journal of Functional Programming 10, 1 (2000), 19–56. Google ScholarDigital Library
Index Terms
- Relational algebra by way of adjunctions
Recommendations
Monads and Adjunctions for Global Exceptions
In this paper, we look at two categorical accounts of computational effects (strong monad as a model of the monadic metalanguage, adjunction as a model of call-by-push-value with stacks), and we adapt them to incorporate global exceptions. In each case, ...
The algebraic approach II: dioids, quantales and monads
RelMiCS'08/AKA'08: Proceedings of the 10th international conference on Relational and kleene algebra methods in computer science, and 5th international conference on Applications of kleene algebraThe algebraic approach to formal language and automata theory is a continuation of the earliest traditions in these fields which had sought to represent languages, translations and other computations as expressions (e.g. regular expressions) in suitably-...
Flexible presentations of graded monads
A large class of monads used to model computational effects have natural presentations by operations and equations, for example, the list monad can be presented by a constant and a binary operation subject to unitality and associativity. Graded monads ...
Comments