Abstract
Gradual typing has emerged as the tonic for programmers with a thirst for a blend of static and dynamic typing. Contracts provide a lightweight form of gradual typing as they can be implemented as a library, rather than requiring a gradual type system.
Intersection and union types are well suited to static and dynamic languages: intersection encodes overloaded functions; union encodes uncertain data arising from branching code. We extend the untyped lambda calculus with contracts for monitoring higher-order intersection and union types, for the first time giving a uniform treatment to both. Each operator requires a single reduction rule that does not depend on the constituent types or the context of the operator.
We present a new method for defining contract satisfaction based on blame behaviour. A value positively satisfies a type if applying a contract of that type can never elicit positive blame. A continuation negatively satisfies a type if applying a contract of that type can never elicit negative blame. We supplement our definition of satisfaction with a series of monitoring properties that satisfying values and continuations should have.
Supplemental Material
- Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. 2017. Theorems for Free for Free: Parametricity, With and Without Types. In ACM International Conference on Functional Programming (ICFP).Google Scholar
- Franco Barbanera and Mariangiola Dezani-Ciancaglini. 1991. Intersection and Union Types. In Theoretical Aspects of Computer Software, Takayasu Ito and Albert R. Meyer (Eds.). Springer Berlin Heidelberg. Google Scholar
Digital Library
- Gavin Bierman, Martín Abadi, and Mads Torgersen. 2014. Understanding TypeScript. In European Conference on ObjectOriented Programming (ECOOP). Google Scholar
Digital Library
- Matthias Blume and David McAllester. 2006. Sound and complete models of contracts. Journal of Functional Programming 16, 4-5 (2006), 375–414. Google Scholar
Digital Library
- Giuseppe Castagna and Victor Lanvin. 2017. Gradual Typing with Union and Intersection Types. In ACM International Conference on Functional Programming (ICFP).Google Scholar
- Avik Chaudhuri, Panagiotis Vekris, Sam Goldman, Marshall Roch, and Gabriel Levi. 2017. Fast and Precise Type Checking for JavaScript. In ACM Conference on Object-Oriented Programming: Systems, Languages, and Applications (OOPSLA).Google Scholar
- Mario Coppo and Mariangiola Dezani-Ciancaglini. 1978. A new type assignment for λ-terms. 19 (1978), 139–156.Google Scholar
- Rowan Davies and Frank Pfenning. 2000. Intersection Types and Computational Effects. In ACM International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Christos Dimoulas and Matthias Felleisen. 2011. On contract satisfaction in a higher-order world. ACM Transactions on Programming Languages and Systems (TOPLAS) 33, 5 (2011), 16. Google Scholar
Digital Library
- Christos Dimoulas, Robert Bruce Findler, Cormac Flanagan, and Matthias Felleisen. 2011. Correct Blame for Contracts: No More Scapegoating. In ACM Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Christos Dimoulas, Sam Tobin-Hochstadt, and Matthias Felleisen. 2012. Complete Monitors for Behavioral Contracts. In European Symposium on Programming (ESOP). Google Scholar
Digital Library
- Joshua Dunfield and Frank Pfenning. 2003. Type Assignment for Intersections and Unions in Call-by-Value Languages. In Foundations of Software Science and Computation Structures. Google Scholar
Digital Library
- Robert Bruce Findler and Matthias Blume. 2006. Contracts as Pairs of Projections. In International Symposium on Functional and Logic Programming (FLOPS), Masami Hagiya and Philip Wadler (Eds.). Google Scholar
Digital Library
- Robert Bruce Findler, Matthias Blume, and Matthias Felleisen. 2004. An investigation of contracts as projections. University of Chicago Technical Report, TR-2004-02 (2004).Google Scholar
- Robert Bruce Findler and Matthias Felleisen. 2002. Contracts for Higher-order Functions. In ACM International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting Gradual Typing. In ACM Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Arjun Guha, Jacob Matthews, Robert Bruce Findler, and Shriram Krishnamurthi. 2007. Relationally-parametric Polymorphic Contracts. In Dynamic Languages Symposium (DLS). Google Scholar
Digital Library
- Atsushi Igarashi, Peter Thiemann, Vasco T. Vasconcelos, and Philip Wadler. 2017b. Gradual Session Types. In ACM International Conference on Functional Programming (ICFP).Google Scholar
- Yuu Igarashi, Taro Sekiyama, and Atsushi Igarashi. 2017a. On Polymorphic Gradual Typing. In ACM International Conference on Functional Programming (ICFP).Google Scholar
- Matthias Keil and Peter Thiemann. 2015a. Blame assignment for higher-order contracts with intersection and union. In ACM International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Matthias Keil and Peter Thiemann. 2015b. TreatJS: Higher-Order Contracts for JavaScripts. In European Conference on Object-Oriented Programming (ECOOP) (Leibniz International Proceedings in Informatics (LIPIcs)). 28–51.Google Scholar
- Bertrand Meyer. 1988. Object-Oriented Software Construction. Prentice-Hall, Inc. Google Scholar
Digital Library
- Bertrand Meyer. 1992. Eiffel: The Language. Prentice-Hall, Inc. Google Scholar
Digital Library
- Benjamin C. Pierce. 1993. Intersection Types and Bounded Polymorphism. In Typed Lambda Calculi and Applications. Springer Berlin Heidelberg. Google Scholar
Digital Library
- Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop (Scheme).Google Scholar
- Jeremy G. Siek and Sam Tobin-Hochstadt. 2016. The Recursive Union of Some Gradual Types. Springer International Publishing.Google Scholar
- Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. 2015a. Refined Criteria for Gradual Typing. In 1st Summit on Advances in Programming Languages (SNAPL 2015) (Leibniz International Proceedings in Informatics (LIPIcs)).Google Scholar
- Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015b. Monotonic References for Efficient Gradual Typing. In European Symposium on Programming (ESOP). Google Scholar
Digital Library
- Cameron Swords, Amr Sabry, and Sam Tobin-Hochstadt. 2018. An extended account of contract monitoring strategies as patterns of communication. Journal of Functional Programming 28 (2018), e4.Google Scholar
Cross Ref
- Sam Tobin-Hochstadt and Matthias Felleisen. 2006. Interlanguage Migration: From Scripts to Programs. In Dynamic Languages Symposium (DLS). Google Scholar
Digital Library
- Matías Toro and Éric Tanter. 2017. A Gradual Interpretation of Union Types. In Static Analysis.Google Scholar
- Jesse A. Tov and Riccardo Pucella. 2010. Stateful Contracts for Affine Types. In European Symposium on Programming (ESOP). Google Scholar
Digital Library
- Philip Wadler. 2015. A Complement to Blame. In SNAPL.Google Scholar
- Philip Wadler and Robert Bruce Findler. 2009. Well-Typed Programs Can’t Be Blamed. In European Symposium on Programming (ESOP). 1–16. Google Scholar
Digital Library
- Dana N. Xu, Simon Peyton Jones, and Koen Claessen. 2009. Static Contract Checking for Haskell. In ACM Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
Index Terms
The root cause of blame: contracts for intersection and union types
Recommendations
Blame assignment for higher-order contracts with intersection and union
ICFP '15We present an untyped calculus of blame assignment for a higher-order contract system with two new operators: intersection and union. The specification of these operators is based on the corresponding type theoretic constructions. This connection makes ...
Gradual typing with union and intersection types
We propose a type system for functional languages with gradual types and set-theoretic type connectives and prove its soundness. In particular, we show how to lift the definition of the domain and result type of an application from non-gradual types to ...
Collapsible contracts: fixing a pathology of gradual typing
The promise of gradual typing is that programmers should get the best of both worlds: the static guarantees of static types, and the dynamic flexibility of untyped programming. This is an enticing benefit, but one that, in practice, may carry ...






Comments