Abstract
The pattern-match safety problem is to verify that a given functional program will never crash due to non-exhaustive patterns in its function definitions. We present a refinement type system that can be used to solve this problem. The system extends ML-style type systems with algebraic datatypes by a limited form of structural subtyping and environment-level intersection. We describe a fully automatic, sound and complete type inference procedure for this system which, under reasonable assumptions, is worst-case linear-time in the program size. Compositionality is essential to obtaining this complexity guarantee. A prototype implementation for Haskell is able to analyse a selection of packages from the Hackage database in a few hundred milliseconds.
- Alexander Aiken. 1999. Introduction to set constraint-based program analysis. Science of Computer Programming 35, 2 ( 1999 ), 79-111. https://doi.org/10.1016/S0167-6423 ( 99 ) 00007-6 Google Scholar
Digital Library
- Alexander Aiken and Edward L. Wimmers. 1992. Solving Systems of Set Constraints (Extended Abstract). In Proceedings of the Seventh Annual Symposium on Logic in Computer Science (LICS '92), Santa Cruz, California, USA, June 22-25, 1992. 329-340.Google Scholar
- Alexander Aiken and Edward L. Wimmers. 1993. Type Inclusion Constraints and Type Inference. In FPCA. 31-41.Google Scholar
Digital Library
- Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994a. Soft Typing with Conditional Types. In Conference Record of POPL'94: 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Portland, Oregon, USA, January 17-21, 1994. 163-173.Google Scholar
Digital Library
- Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994b. Soft typing with conditional types. In Proceedings of the 21st ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 163-173. https://doi.org/10.1145/174675.177847 Google Scholar
Digital Library
- Alexander Aiken, Edward L. Wimmers, and Jens Palsberg. 1999. Optimal Representations of Polymorphic Types with Subtyping. Higher-Order and Symbolic Computation 12, 3 ( 1999 ), 237-282. https://doi.org/10.1023/A:1010056315933 Google Scholar
Digital Library
- Roberto M. Amadio and Luca Cardelli. 1993. Subtyping recursive types. ACM Trans. Program. Lang. Syst. 15, 4 ( 1993 ), 575-631. https://doi.org/10.1145/155183.155231 Google Scholar
Digital Library
- Leo Bachmair, Harald Ganzinger, and Uwe Waldmann. 1993. Set constraints are the monadic class. In Proceedings Eighth Annual IEEE Symposium on Logic in Computer Science. IEEE, 75-83.Google Scholar
Cross Ref
- Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyen. 2016. Set-theoretic types for polymorphic variants. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, 378-391. https://doi.org/10.1145/2951913.2951928 Google Scholar
Digital Library
- Giuseppe Castagna and Zhiwu Xu. 2011. Set-theoretic foundation of parametric polymorphism and subtyping. In Proceedings of the 16th ACM SIGPLAN international conference on Functional programming. Association for Computing Machinery, 94-106. https://doi.org/10.1145/2034773.2034788 Google Scholar
Digital Library
- Toby Cathcart Burn, C.-H. Luke Ong, and Steven J. Ramsay. 2017. Higher-order constrained horn clauses for verification. Proc. ACM Program. Lang. 2, POPL ( 2017 ), Article 11. https://doi.org/10.1145/3158099 Google Scholar
Digital Library
- Stephen Dolan and Alan Mycroft. 2017. Polymorphism, subtyping, and type inference in MLsub. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. Association for Computing Machinery, 60-72. https://doi.org/10.1145/3009837.3009882 Google Scholar
Digital Library
- Joshua Dunfield. 2007. Refined typechecking with Stardust. In Proceedings of the 2007 workshop on Programming languages meets program verification. Association for Computing Machinery, 21-32. https://doi.org/10.1145/1292597.1292602 Google Scholar
Digital Library
- Joshua Dunfield. 2017. Extensible Datasort Refinements. In European Symposium on Programming Languages and Systems, Hongseok Yang (Ed.). Springer Berlin Heidelberg, 476-503. https://doi.org/10.1007/978-3-662-54434-1_18 Google Scholar
Cross Ref
- Joseph Eremondi. 2019. Set Constraints, Pattern Match Analysis, and SMT. In Trends in Functional Programming-20th International Symposium, TFP 2019, Vancouver, BC, Canada, June 12-14, 2019, Revised Selected Papers (Lecture Notes in Computer Science), William J. Bowman and Ronald Garcia (Eds.), Vol. 12053. Springer, 121-141. https://doi.org/10.1007/978-3-030-47147-7_6 Google Scholar
Cross Ref
- Manuel Fähndrich and Alexander Aiken. 1996. Making Set-Constraint Based Program Analyses Scale. In First Workshop on Set Constraints at CP' 96.Google Scholar
- Manuel Fähndrich, Jefrey S. Foster, Zhendong Su, and Alexander Aiken. 1998. Partial online cycle elimination in inclusion constraint graphs. In Proceedings of the ACM SIGPLAN 1998 conference on Programming language design and implementation. Association for Computing Machinery, 85-96. https://doi.org/10.1145/277650.277667 Google Scholar
Digital Library
- Cormac Flanagan and Matthias Felleisen. 1999. Componential set-based analysis. ACM Trans. Program. Lang. Syst. 21, 2 ( 1999 ), 370-416. https://doi.org/10.1145/316686.316703 Google Scholar
Digital Library
- Tim Freeman and Frank Pfenning. 1991. Refinement types for ML. In Proceedings of the ACM SIGPLAN 1991 conference on Programming language design and implementation. Association for Computing Machinery, 268-277. https://doi.org/10. 1145/113445.113468 Google Scholar
Digital Library
- Jacques Garrigue. 2002. Simple Type Inference for Structural Polymorphism. In International Workshop on Foundations of Object-Oriented Languages (FOOL).Google Scholar
- Sebastian Graf, Simon Peyton Jones, and Ryan G. Scott. 2020. Lower your guards: a compositional pattern-match coverage checker. Proc. ACM Program. Lang. 4, ICFP ( 2020 ), 107 : 1-107 : 30. https://doi.org/10.1145/3408989 Google Scholar
Digital Library
- Jörgen Gustavsson and Josef Svenningsson. 2001. Constraint Abstractions. In Symposium on Programs as Data Objects, Olivier Danvy and Andrzej Filinski (Eds.). Springer Berlin Heidelberg, 63-83.Google Scholar
- John Harrison. 2009. Handbook of Practical Logic and Automated Reasoning. Cambridge University Press.Google Scholar
Digital Library
- Nevin Heintze. 1994. Set-based analysis of ML programs. In Proceedings of the 1994 ACM conference on LISP and functional programming. Association for Computing Machinery, 306-317. https://doi.org/10.1145/182409.182495 Google Scholar
Digital Library
- Nevin Heintze, Spiro Michaylov, and Peter Stuckey. 1992. CLP(R) and some electrical engineering problems. Journal of Automated Reasoning 9, 2 ( 1992 ), 231-260.Google Scholar
Digital Library
- Nevin Charles Heintze. 1992. Set based program analysis. Thesis.Google Scholar
- My Hoang and John C. Mitchell. 1995. Lower bounds on type inference with subtypes. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 176-185. https://doi.org/10.1145/199448.199481 Google Scholar
Digital Library
- Naoki Kobayashi. 2013. Model Checking Higher-Order Programs. J. ACM 60, 3 ( 2013 ), Article 20. https://doi.org/10.1145/ 2487241.2487246 Google Scholar
Digital Library
- N. Kobayashi and C. L. Ong. 2009. A Type System Equivalent to the Modal Mu-Calculus Model Checking of Higher-Order Recursion Schemes. In IEEE Symposium on Logic In Computer Science. 179-188. https://doi.org/10.1109/LICS. 2009.29 Google Scholar
Digital Library
- Naoki Kobayashi, Takeshi Tsukada, and Keiichi Watanabe. 2018. Higher-Order Program Verification via HFL Model Checking. In European Symposium on Programming Languages and Systems, Amal Ahmed (Ed.). Springer International Publishing, 711-738.Google Scholar
Cross Ref
- Dexter Kozen, Jens Palsberg, and Michael I. Schwartzbach. 1995. Eficient recursive subtyping. Mathematical Structures in Computer Science 5, 1 ( 1995 ), 113-125. https://doi.org/10.1017/S0960129500000657 Google Scholar
Cross Ref
- Luc Maranget. 2007. Warnings for pattern matching. J. Funct. Program. 17, 3 ( 2007 ), 387-421. https://doi.org/10.1017/ S0956796807006223 Google Scholar
Cross Ref
- Neil Mitchell and Colin Runciman. 2008. Not all patterns, but enough: an automatic verifier for partial but suficient pattern matching. In Proceedings of the first ACM SIGPLAN symposium on Haskell. Association for Computing Machinery, 49-60. https://doi.org/10.1145/1411286.1411293 Google Scholar
Digital Library
- Phuc C. Nguyen, Sam Tobin-Hochstadt, and David Van Horn. 2014. Soft contract verification. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014, Johan Jeuring and Manuel M. T. Chakravarty (Eds.). ACM, 139-152. https://doi.org/10.1145/2628136.2628156 Google Scholar
Digital Library
- Martin Odersky, Martin Sulzmann, and Martin Wehr. 1999. Type Inference with Constrained Types. TAPOS 5, 1 ( 1999 ), 35-55.Google Scholar
- C.-H. Luke Ong and Steven J. Ramsay. 2011. Verifying higher-order functional programs with pattern-matching algebraic data types. In Proceedings of the 38th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 587-598. https://doi.org/10.1145/1926385.1926453 Google Scholar
Digital Library
- C. L. Ong. 2006. On Model-Checking Trees Generated by Higher-Order Recursion Schemes. In IEEE Symposium on Logic in Computer Science. 81-90. https://doi.org/10.1109/LICS. 2006.38 Google Scholar
Digital Library
- Matthew Pickering, Gergo Érdi, Simon Peyton Jones, and Richard A. Eisenberg. 2016. Pattern synonyms. In Proceedings of the 9th International Symposium on Haskell, Haskell 2016, Nara, Japan, September 22-23, 2016, Geofrey Mainland (Ed.). ACM, 80-91. https://doi.org/10.1145/2976002.2976013 Google Scholar
Digital Library
- François Pottier. 1998. Type inference in the presence of subtyping: from theory to practice. Thesis.Google Scholar
- François Pottier. 2000. A Versatile Constraint-Based Type Inference System. Nordic J. of Computing 7, 4 (Dec. 2000 ), 312-347.Google Scholar
- François Pottier. 2001. Simplifying Subtyping Constraints: A Theory. Information and Computation 170, 2 ( 2001 ), 153-183. https://doi.org/10.1006/inco. 2001.2963 Google Scholar
Digital Library
- Jakob Rehof. 1997. Minimal typings in atomic subtyping. In Proceedings of the 24th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 278-291. https://doi.org/10.1145/263699. 263738 Google Scholar
Digital Library
- Jakob Rehof and Torben Æ. Mogensen. 1999. Tractable constraints in finite semilattices. Science of Computer Programming 35, 2 ( 1999 ), 191-221.Google Scholar
- Patrick M. Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid types. In Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation. Association for Computing Machinery, 159-169. https://doi.org/10.1145/1375581.1375602 Google Scholar
Digital Library
- Zhendong Su, Manuel Fähndrich, and Alexander Aiken. 2000. Projection merging: reducing redundancies in inclusion constraint graphs. In Proceedings of the 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 81-95. https://doi.org/10.1145/325694.325706 Google Scholar
Digital Library
- Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with Type Equality Coercions. In Proceedings of the 2007 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI '07). Association for Computing Machinery, New York, NY, USA, 53-66. https://doi.org/10.1145/ 1190315.1190324 Google Scholar
Digital Library
- Tachio Terauchi. 2010. Dependent types from counterexamples. In Proceedings of the 37th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 119-130. https://doi.org/10. 1145/1706299.1706315 Google Scholar
Digital Library
- Valery Trifonov and Scott Smith. 1996. Subtyping constrained types. In Static Analysis Symposium, Radhia Cousot and David A. Schmidt (Eds.). Springer Berlin Heidelberg, 349-365.Google Scholar
Cross Ref
- Hiroshi Unno and Naoki Kobayashi. 2009. Dependent type inference with interpolants. In Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming. Association for Computing Machinery, 277-288. https://doi.org/10.1145/1599410.1599445 Google Scholar
Digital Library
- Niki Vazou, Alexander Bakst, and Ranjit Jhala. 2015. Bounded refinement types. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, 48-61. https://doi.org/10. 1145/2784731.2784745 Google Scholar
Digital Library
- Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton-Jones. 2014. Refinement types for Haskell. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming. Association for Computing Machinery, 269-282. https://doi.org/10.1145/2628136.2628161 Google Scholar
Digital Library
- Mahesh Viswanathan and Ramesh Viswanathan. 2004. A Higher Order Modal Fixed Point Logic. In CONCUR 2004-Concurrency Theory, Philippa Gardner and Nobuko Yoshida (Eds.). Springer Berlin Heidelberg, 512-528.Google Scholar
Cross Ref
- Dimitrios Vytiniotis, Simon L. Peyton Jones, Koen Claessen, and Dan Rosén. 2013. HALO: haskell to logic through denotational semantics. In The 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '13, Rome, Italy-January 23-25, 2013, Roberto Giacobazzi and Radhia Cousot (Eds.). ACM, 431-442. https: //doi.org/10.1145/2429069.2429121 Google Scholar
Digital Library
- Hongwei Xi and Frank Pfenning. 1999. Dependent types in practical programming. In Proceedings of the 26th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 214-227. https://doi.org/10.1145/292540.292560 Google Scholar
Digital Library
- Dana N. Xu, Simon L. Peyton Jones, and Koen Claessen. 2009. Static contract checking for Haskell. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21-23, 2009, Zhong Shao and Benjamin C. Pierce (Eds.). ACM, 41-52. https://doi.org/10.1145/1480881.1480889 Google Scholar
Digital Library
Index Terms
Intensional datatype refinement: with application to scalable verification of pattern-match safety
Recommendations
Higher-order constrained horn clauses for verification
Motivated by applications in automated verification of higher-order functional programs, we develop a notion of constrained Horn clauses in higher-order logic and a decision problem concerning their satisfiability. We show that, although satisfiable ...
Refinement types for Haskell
PLPV '14: Proceedings of the ACM SIGPLAN 2014 Workshop on Programming Languages meets Program VerificationWe present LiquidHaskell (http://goto.ucsd.edu/liquid), an automatic verifier for Haskell. LiquidHaskell uses Refinement types, a restricted form of dependent types where relationships between values are encoded by decorating types with logical ...
Gradual refinement types
POPL '17Refinement types are an effective language-based verification technique. However, as any expressive typing discipline, its strength is its weakness, imposing sometimes undesired rigidity. Guided by abstract interpretation, we extend the gradual typing ...






Comments