Strongly Normalizing Higher-Order Relational Queries

Authors Wilmer Ricciotti , James Cheney

Thumbnail PDF


  • Filesize: 0.58 MB
  • 22 pages

Document Identifiers

Author Details

Wilmer Ricciotti
  • Laboratory for Foundations of Computer Science, University of Edinburgh, UK
James Cheney
  • Laboratory for Foundations of Computer Science, University of Edinburgh, UK


We are grateful to Philip Wadler, Sam Lindley, and the anonymous reviewers for their comments and suggestions.

Cite AsGet BibTex

Wilmer Ricciotti and James Cheney. Strongly Normalizing Higher-Order Relational Queries. In 5th International Conference on Formal Structures for Computation and Deduction (FSCD 2020). Leibniz International Proceedings in Informatics (LIPIcs), Volume 167, pp. 28:1-28:22, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2020)


Language-integrated query is a powerful programming construct allowing database queries and ordinary program code to interoperate seamlessly and safely. Language-integrated query techniques rely on classical results about monadic comprehension calculi, including the conservativity theorem for nested relational calculus. Conservativity implies that query expressions can freely use nesting and unnesting, yet as long as the query result type is a flat relation, these capabilities do not lead to an increase in expressiveness over flat relational queries. Wong showed how such queries can be translated to SQL via a constructive rewriting algorithm, and Cooper and others advocated higher-order nested relational calculi as a basis for language-integrated queries in functional languages such as Links and F#. However there is no published proof of the central strong normalization property for higher-order nested relational queries: a previous proof attempt does not deal correctly with rewrite rules that duplicate subterms. This paper fills the gap in the literature, explaining the difficulty with a previous proof attempt, and showing how to extend the ⊤⊤-lifting approach of Lindley and Stark to accommodate duplicating rewrites. We also sketch how to extend the proof to a recently-introduced calculus for heterogeneous queries mixing set and multiset semantics.

Subject Classification

ACM Subject Classification
  • Theory of computation → Type theory
  • Strong normalization
  • ⊤⊤-lifting
  • Nested relational calculus
  • Language-integrated query


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Véronique Benzaken and Evelyne Contejean. A Coq mechanised formal semantics for realistic SQL queries: formally reconciling SQL and bag relational algebra. In CPP 2019, pages 249-261, 2019. URL:
  2. Peter Buneman, Shamim Naqvi, Val Tannen, and Limsoon Wong. Principles of programming with complex objects and collection types. Theor. Comput. Sci., 149(1), 1995. URL:
  3. James Cheney, Sam Lindley, and Philip Wadler. A practical theory of language-integrated query. In ICFP, 2013. URL:
  4. James Cheney, Sam Lindley, and Philip Wadler. Query shredding: efficient relational evaluation of queries over nested multisets. In SIGMOD, pages 1027-1038. ACM, 2014. URL:
  5. Shumo Chu, Konstantin Weitz, Alvin Cheung, and Dan Suciu. HoTTSQL: Proving query rewrites with univalent SQL semantics. In PLDI, pages 510-524. ACM, 2017. URL:
  6. Ezra Cooper. Programming language features for web application development. PhD thesis, University of Edinburgh, 2009. Google Scholar
  7. Ezra Cooper. The script-writer’s dream: How to write great SQL in your own language, and be sure it will succeed. In DBPL, 2009. URL:
  8. Ezra Cooper, Sam Lindley, Philip Wadler, and Jeremy Yallop. Links: web programming without tiers. In FMCO, 2007. URL:
  9. Jean-Yves Girard, Yves Lafont, and Paul Taylor. Proofs and Types. Cambridge University Press, 1989. Google Scholar
  10. Paolo Guagliardo and Leonid Libkin. A formal semantics of SQL queries, its validation, and applications. PVLDB, 2017. URL:
  11. Oleg Kiselyov and Tatsuya Katsushima. Sound and efficient language-integrated query - maintaining the ORDER. In APLAS 2017, pages 364-383, 2017. URL:
  12. Leonid Libkin and Limsoon Wong. Conservativity of nested relational calculi with internal generic functions. Inf. Process. Lett., 49(6):273-280, 1994. URL:
  13. Leonid Libkin and Limsoon Wong. Query languages for bags and aggregate functions. J. Comput. Syst. Sci., 55(2), 1997. URL:
  14. Sam Lindley and James Cheney. Row-based effect types for database integration. In TLDI, 2012. URL:
  15. Sam Lindley and Ian Stark. Reducibility and ⊤⊤-lifting for computation types. In TLCA, 2005. URL:
  16. Erik Meijer, Brian Beckman, and Gavin M. Bierman. LINQ: reconciling object, relations and XML in the .NET framework. In SIGMOD, 2006. URL:
  17. Jan Paredaens and Dirk Van Gucht. Converting nested algebra expressions into flat algebra expressions. ACM Trans. Database Syst., 17(1), 1992. URL:
  18. Andrew M. Pitts. Parametric polymorphism and operational equivalence (preliminary version). In HOOTS II, volume 10, pages 2-27, 1998. URL:
  19. W. Ricciotti and J. Cheney. Strongly Normalizing Audited Computation. In V. Goranko and M. Dam, editors, CSL 2017, volume 82 of Leibniz International Proceedings in Informatics (LIPIcs), pages 36:1-36:21. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2017. URL:
  20. Wilmer Ricciotti and James Cheney. Mixing set and bag semantics. In DBPL, pages 70-73, 2019. URL:
  21. Philip Trinder and Philip Wadler. Improving list comprehension database queries. In TENCON '89., 1989. URL:
  22. Philip Wadler. Comprehending monads. Math. Struct. in Comp. Sci., 2(4), 1992. URL:
  23. Limsoon Wong. Normal forms and conservative extension properties for query languages over collection types. J. Comput. Syst. Sci., 52(3), 1996. URL:
  24. Limsoon Wong. Kleisli, a functional query system. J. Funct. Programming, 10(1), 2000. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail