skip to main content
10.1145/3546189.3549919acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article
Open Access
Artifacts Available / v1.1

How to safely use extensionality in Liquid Haskell

Published:06 September 2022Publication History

ABSTRACT

Refinement type checkers are a powerful way to reason about functional programs. For example, one can prove properties of a slow, specification implementation and port the proofs to an optimized pure implementation that behaves the same. But to reason about higher-order programs, we must reason about equalities between functions: we need a consistent encoding of functional extensionality.

A natural but naive phrasing of the functional extensionality axiom (funExt) is inconsistent in refinement type systems with semantic subtyping and polymorphism: if we assume funExt, then we can prove false. We demonstrate the inconsistency and develop a new approach to equality in Liquid Haskell: we define a propositional equality in a library we call PEq. Using PEq avoids the inconsistency while proving useful equalities at higher types; we demonstrate its use in several case studies. We validate PEq by building a model and developing its metatheory. Additionally, we prove metaproperties of PEq inside Liquid Haskell itself using an unnamed folklore technique, which we dub 'classy induction'.

References

  1. Thorsten Altenkirch and Conor McBride. 2006. Towards Observational Type Theory. http://www.strictlypositive.org/ott.pdf Unpublished manuscript Google ScholarGoogle Scholar
  2. Carlo Angiuli, Evan Cavallo, Kuen-Bang Hou (Favonia), Robert Harper, and Jonathan Sterling. 2018. The RedPRL Proof Assistant (Invited Paper). In Theoretical Computer Science. https://doi.org/10.4204/eptcs.274.1 Google ScholarGoogle ScholarCross RefCross Ref
  3. Carlo Angiuli, Kuen-Bang Hou (Favonia), and Robert Harper. 2018. Cartesian Cubical Computational Type Theory: Constructive Reasoning with Paths and Equalities. In Computer Science Logic. http://drops.dagstuhl.de/opus/volltexte/2018/9673 Google ScholarGoogle Scholar
  4. Robert Atkey and Patricia Johann. 2015. Interleaving Data and Effects. In Journal of Functional Programming. https://doi.org/10.1017/S0956796815000209 Google ScholarGoogle ScholarCross RefCross Ref
  5. Haniel Barbosa, Andrew Reynolds, Daniel El Ouraoui, Cesare Tinelli, and Clark Barrett. 2019. Extending SMT Solvers to Higher-Order Logic. In CADE. isbn:978-3-030-29436-6 https://doi.org/10.1007/978-3-030-29436-6_3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Clark Barrett, Aaron Stump, and Cesare Tinelli. 2010. The SMT-LIB Standard: Version 2.0. Department of Computer Science, The University of Iowa. www.SMT-LIB.org Google ScholarGoogle Scholar
  7. Gavin M. Bierman, Andrew D. Gordon, Catalin Hritcu, and David E. Langworthy. 2012. Semantic Subtyping with an SMT Solver. In Journal of Functional Programming. https://doi.org/10.1017/S0956796812000032 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Simon Boulier, Pierre-Marie Pédrot, and Nicolas Tabareau. 2017. The Next 700 Syntactical Models of Type Theory. In Certified Programs and Proofs. https://doi.org/10.1145/3018610.3018620 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Koen Claessen and John Hughes. 2002. Testing Monadic Code with QuickCheck. In GPCE. https://doi.org/10.1145/636517.636527 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Cyril Cohen, Thierry Coquand, Simon Huber, and Anders Mörtberg. 2015. Cubical Type Theory: a Constructive Interpretation of the Univalence Axiom. In Types for Proofs and Programs. https://doi.org/10.4230/LIPIcs.TYPES.2015.5 Google ScholarGoogle ScholarCross RefCross Ref
  11. Robert L. Constable, Stuart F. Allen, Mark Bromley, Rance Cleaveland, J. F. Cremer, R. W. Harper, Douglas J. Howe, Todd B. Knoblock, N. P. Mendler, Prakash Panangaden, James T. Sasaki, and Scott F. Smith. 1986. Implementing Mathematics with the Nuprl Proof Development System. Prentice Hall. isbn:978-0-13-451832-9 http://dl.acm.org/citation.cfm?id=10510 Google ScholarGoogle Scholar
  12. Robert L Constable and Scott Fraser Smith. 1987. Partial objects in constructive type theory. Cornell University. https://dl.acm.org/doi/10.5555/866226 Google ScholarGoogle Scholar
  13. Pierre-Évariste Dagand, Nicolas Tabareau, and Éric Tanter. 2018. Foundations of Dependent Interoperability. In Journal of Functional Programming. https://doi.org/10.1017/S0956796818000011 Google ScholarGoogle ScholarCross RefCross Ref
  14. Github FStarLang. 2018. Functional Equality Discussions in F*. https://github.com/FStarLang/FStar/blob/cba5383bd0e84140a00422875de21a8a77bae116/ulib/FStar.FunctionalExtensionality.fsti#L133-L134 Google ScholarGoogle Scholar
  15. Jeremy Gibbons and Ralf Hinze. 2011. Just Do It: Simple Monadic Equational Reasoning. In ICFP. https://doi.org/10.1145/2034773.2034777 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Michael Greenberg, Benjamin C. Pierce, and Stephanie Weirich. 2012. Contracts Made Manifest. In Journal of Functional Programming. https://doi.org/10.1017/S0956796812000135 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Louis-Julien Guillemette and Stefan Monnier. 2008. A Type-Preserving Compiler in Haskell. In ICFP. isbn:9781595939197 https://doi.org/10.1145/1411204.1411218 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Kenneth Knowles and Cormac Flanagan. 2010. Hybrid Type Checking. In ACM Transactions on Programming Languages and Systems. https://doi.org/10.1145/1667048.1667051 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Kenneth Knowles, Aaron Tomb, Jessica Gronski, Stephen N. Freund, and Cormac Flanagan. 2006. Sage: Hybrid checking for flexible specifications. In Scheme and Functional Programming Workshop. http://www.cs.williams.edu/~freund/papers/06-sfp.pdf Google ScholarGoogle Scholar
  20. Leonidas Lampropoulos, Zoe Paraskevopoulou, and Benjamin C. Pierce. 2018. Generating Good Generators for Inductive Relations. In POPL. https://doi.org/10.1145/3158133 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. K. Rustan M. Leino. 2012. Developing verified programs with Dafny. In High Integrity Language Technology. https://doi.org/10.1145/2402676.2402682 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Yiyun Liu, James Parker, Patrick Redmond, Lindsey Kuper, Michael Hicks, and Niki Vazou. 2020. Verifying Replicated Data Types with Typeclass Refinements in Liquid Haskell. In OOPSLA. https://doi.org/10.1145/3428284 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Kenji Maillard, Danel Ahman, Robert Atkey, Guido Martínez, Cătălin Hriţcu, Exequiel Rivas, and Éric Tanter. 2019. Dijkstra Monads for All. In ICFP. https://doi.org/10.1145/3341708 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. E. Moggi. 1989. Computational Lambda-Calculus and Monads. In LICS. https://doi.org/10.1109/LICS.1989.39155 Google ScholarGoogle ScholarCross RefCross Ref
  25. Benjamin Moon, Harley Eades III, and Dominic Orchard. 2021. Graded Modal Dependent Type Theory. In ESOP, Nobuko Yoshida (Ed.). https://doi.org/10.1007/978-3-030-72019-3_17 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Aleksandar Nanevski, Greg Morrisett, and Lars Birkedal. 2006. Polymorphism and Separation in Hoare Type Theory. In ICFP. isbn:1595933093 https://doi.org/10.1145/1159803.1159812 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Tobias Nipkow and Christian Prehofer. 1993. Type Checking Type Classes. In POPL. isbn:0897915607 https://doi.org/10.1145/158511.158698 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Tobias Nipkow and Gregor Snelting. 1991. Type Classes and Overloading Resolution via Order-Sorted Unification. In Functional Programming Languages and Computer Architecture. https://doi.org/10.1007/3540543961_1 Google ScholarGoogle ScholarCross RefCross Ref
  29. Xinming Ou, Gang Tan, Yitzhak Mandelbaum, and David Walker. 2004. Dynamic Typing with Dependent Types. In International Conference on Theoretical Computer Science. https://doi.org/10.1007/1-4020-8141-3_34 Google ScholarGoogle ScholarCross RefCross Ref
  30. Patrick M. Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid Types. In PLDI. isbn:978-1-59593-860-2 https://doi.org/10.1145/1375581.1375602 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. John Rushby, Sam Owre, and Natarajan Shankar. 1998. Subtypes for Specifications: Predicate Subtyping in PVS. IEEE Transactions on Software Engineering, https://doi.org/10.1109/32.713327 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Taro Sekiyama, Atsushi Igarashi, and Michael Greenberg. 2017. Polymorphic Manifest Contracts, Revised and Resolved. In ACM Transactions on Programming Languages and Systems. https://doi.org/10.1145/2994594 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Lucas Silver and Steve Zdancewic. 2021. Dijkstra Monads Forever: Termination-Sensitive Specifications for Interaction Trees. In POPL. https://doi.org/10.1145/3434307 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Matthieu Sozeau. 2008. Un environnement pour la programmation avec types dépendants. Ph. D. Dissertation. Université Paris 11. https://tel.archives-ouvertes.fr/tel-00640052 Google ScholarGoogle Scholar
  35. Matthieu Sozeau and Nicolas Oury. 2008. First-Class Type Classes. In Theorem Proving in Higher Order Logics. https://doi.org/10.1007/978-3-540-71067-7_23 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Jonathan Sterling, Carlo Angiuli, and Daniel Gratzer. 2019. Cubical Syntax for Reflection-Free Extensional Equality. In LIPIcs. https://doi.org/10.4230/LIPIcs.FSCD.2019.31 Google ScholarGoogle ScholarCross RefCross Ref
  37. Nikhil Swamy, Catalin Hritcu, Chantal Keller, Aseem Rastogi, Antoine Delignat-Lavaud, Simon Forest, Karthikeyan Bhargavan, Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean-Karim Zinzindohoué, and Santiago Zanella-Béguelin. 2016. Dependent Types and Multi-Monadic Effects in F*. In POPL. http://dx.doi.org/10.1145/2837614.2837655 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Nikhil Swamy, Joel Weinberger, Cole Schlesinger, Juan Chen, and Benjamin Livshits. 2013. Verifying Higher-Order Programs with the Dijkstra Monad. In PLDI. isbn:9781450320146 https://doi.org/10.1145/2491956.2491978 Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Wouter Swierstra. 2009. A Hoare Logic for the State Monad. In TPHOLs. https://doi.org/10.1007/978-3-642-03359-9_30 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Nicolas Tabareau, Éric Tanter, and Matthieu Sozeau. 2021. The Marriage of Univalence and Parametricity. J. ACM, https://doi.org/10.1145/3429979 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Niki Vazou, Joachim Breitner, Rose Kunkel, David Van Horn, and Graham Hutton. 2018. Theorem Proving for All: Equational Reasoning in Liquid Haskell (Functional Pearl). In Haskell. isbn:978-1-4503-5835-4 https://doi.org/10.1145/3242744.3242756 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Niki Vazou and Michael Greenberg. 2021. How to Safely Use Extensionality in Liquid Haskell (extended version). In CoRR. https://doi.org/10.48550/ARXIV.2103.02177 Google ScholarGoogle Scholar
  43. Niki Vazou, Anish Tondwalkar, Vikraman Choudhury, Ryan G. Scott, Ryan R. Newton, Philip Wadler, and Ranjit Jhala. 2018. Refinement Reflection: Complete Verification with SMT. In POPL. https://doi.org/10.1145/3158141 Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. P. Wadler and S. Blott. 1989. How to Make Ad-Hoc Polymorphism Less Ad Hoc. In POPL. https://doi.org/10.1145/75277.75283 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Stephanie Weirich. 2017. The Influence of Dependent Types (Keynote). In POPL. isbn:9781450346603 https://doi.org/10.1145/3009837.3009923 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Markus Wenzel. 1997. Type Classes and Overloading in HigherOorder Logic. In Theorem Proving in Higher Order Logics. https://doi.org/10.1007/BFb0028402 Google ScholarGoogle ScholarCross RefCross Ref
  47. Hongwei Xi and Frank Pfenning. 1998. Eliminating Array Bound Checking through Dependent Types. In PLDI. https://doi.org/10.1145/277650.277732 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, and Steve Zdancewic. 2019. Interaction Trees: Representing Recursive and Impure Programs in Coq. In POPL. https://doi.org/10.1145/3371119 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. How to safely use extensionality in Liquid Haskell

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in
    • Published in

      cover image ACM Conferences
      Haskell 2022: Proceedings of the 15th ACM SIGPLAN International Haskell Symposium
      September 2022
      136 pages
      ISBN:9781450394383
      DOI:10.1145/3546189

      Copyright © 2022 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 6 September 2022

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article

      Acceptance Rates

      Overall Acceptance Rate57of143submissions,40%

      Upcoming Conference

      ICFP '24

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader