Abstract
We present a simple, practical, and expressive relational nullable type system. A relational nullable type system captures whether an expression may evaluate to null based on its type, but also based on the type of other related expressions. The type system extends the Hindley-Milner type system with Boolean constraints, supports parametric polymorphism, and preserves principal types modulo Boolean equivalence. We show how to support full Hindley-Milner style type inference with an extension of Algorithm W.
We conduct a preliminary study of open source projects showing that there is a need for relational nullable type systems across a wide range of programming languages. The most important findings from the study are: (i) programmers use programming patterns where the nullability of one expression depends on the nullability of other related expressions, (ii) such invariants are commonly enforced with run-time exceptions, and (iii) reasoning about these programming patterns requires not only knowledge of when an expression may evaluate to null, but also when it may evaluate to a non-null value. We incorporate these observations in the design of the proposed relational nullable type system.
Supplemental Material
- Nada Amin and Ross Tate. 2016. Java and Scala’s Type Systems are Unsound: the Existential Crisis of Null Pointers. Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google Scholar
Digital Library
- Franz Baader. 1998. On the Complexity of Boolean Unification. Inform. Process. Lett.. Google Scholar
Digital Library
- Subarno Banerjee, Lazaro Clapp, and Manu Sridharan. 2019. Nullaway: Practical Type-based Null Safety for Java. In Proc. Joint Symposium on European Software Engineering and the Foundations of Software Engineering (ESEC/FSE). Google Scholar
Digital Library
- George Boole. 1847. The mathematical analysis of logic.Google Scholar
- Alexandre Boudet, Jean-Pierre Jouannaud, and Manfred Schmidt-Schauß. 1989. Unification in Boolean Rings and Abelian Groups. Journal of Symbolic Computation. Google Scholar
Digital Library
- Dan Brotherston, Werner Dietl, and Ondřej Lhoták. 2017. Granullar: Gradual Nullable Types for Java. In Proc. International Conference on Compiler Construction (CC). Google Scholar
Digital Library
- Wolfram Buttner and Helmut Simonis. 1987. Embedding Boolean Expressions into Logic Programming. Journal of Symbolic Computation. Google Scholar
Digital Library
- Patrice Chalin and Perry R James. 2007. Non-Null References by Default in Java: Alleviating the Nullity Annotation Burden. In Proc. European Conference on Object-Oriented Programming (ECOOP). Google Scholar
Digital Library
- Olaf Chitil. 2001. Compositional explanation of types and algorithmic debugging of type errors. In Proc. International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Luis Damas. 1984. Type Assignment in Programming Languages. Ph. D. Dissertation. The University of Edinburgh.Google Scholar
- Manuel Fähndrich and K Rustan M Leino. 2003. Declaring and Checking Non-Null Types in an Object-Oriented Language. In Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google Scholar
Digital Library
- Manuel Fähndrich and Songtao Xia. 2007. Establishing Object Invariants with Delayed Types. In Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google Scholar
Digital Library
- Roger Hindley. 1969. The Principal Type-scheme of an Object in Combinatory Logic. Transactions of the American Mathematical Society (AMS).Google Scholar
- Laurent Hubert, Thomas Jensen, and David Pichardie. 2008. Semantic Foundations and Inference of Non-Null Annotations. In International Conference on Formal Methods for Open Object-Based Distributed Systems (FMOODS). Google Scholar
Digital Library
- Mark P Jones. 2003. Qualified Types: Theory and Practice. Cambridge University Press. Google Scholar
Digital Library
- Leopold Löwenheim. 1908. Über das Auflösungsproblem im logischen Klassenkalkul.Google Scholar
- Magnus Madsen and Ondřej Lhoták. 2018. Safe and Sound Program Analysis with Flix. In Proc. International Symposium on Software Testing and Analysis (ISSTA). Google Scholar
Digital Library
- Magnus Madsen and Ondřej Lhoták. 2020. Fixpoints for the Masses: Programming with first-class Datalog Constraints. Proc. of the ACM on Programming Languages, 4, OOPSLA (2020). Google Scholar
Digital Library
- Magnus Madsen and Jaco van de Pol. 2020. Polymorphic Types and Effects with Boolean Unification. Proc. of the ACM on Programming Languages, 4, OOPSLA (2020). Google Scholar
Digital Library
- Magnus Madsen, Ming-Ho Yee, and Ondrej Lhoták. 2016. From Datalog to Flix: A Declarative Language for Fixed Points on Lattices. In Proc. Programming Language Design and Implementation (PLDI). Google Scholar
Digital Library
- Chris Male, David J Pearce, Alex Potanin, and Constantine Dymnikov. 2008. Java Bytecode Verification for NonNull Types. In Proc. International Conference on Compiler Construction (CC). Google Scholar
Digital Library
- Alberto Martelli and Ugo Montanari. 1982. An efficient unification algorithm. ACM Transactions on Programming Languages and Systems (TOPLAS). Google Scholar
Digital Library
- Urusula Martin and Tobias Nipkow. 1989. Boolean Unification - The Story So Far. Journal of Symbolic Computation. Google Scholar
Digital Library
- Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci..Google Scholar
- Abel Nieto, Marianna Rapoport, Gregor Richards, and Ondřej Lhoták. 2020. Blame for Null. In Proc. European Conference on Object-Oriented Programming (ECOOP 2020).Google Scholar
- Abel Nieto, Yaoyu Zhao, Ondřej Lhoták, Angela Chang, and Justin Pu. 2020. Scala with Explicit Nulls. In Proc. European Conference on Object-Oriented Programming (ECOOP 2020).Google Scholar
- Benjamin C Pierce and David N Turner. 2000. Local type inference. ACM Transactions on Programming Languages and Systems (TOPLAS). Google Scholar
Digital Library
- Xin Qi and Andrew C Myers. 2009. Masked Types for Sound Object Initialization. In Proc. Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Patrick M Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid types. In Proc. Programming Language Design and Implementation (PLDI). Google Scholar
Digital Library
- Sergiu Rudeanu. 1974. Boolean Functions and Equations.Google Scholar
- Fausto Spoto. 2008. Nullness Analysis in Boolean Form. In Proc. International Conference on Software Engineering and Formal Methods (SEFM). Google Scholar
Digital Library
- Alexander J Summers and Peter Müller. 2011. Freedom Before Commitment: A Lightweight Type System for Object Initialisation. In Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2010. Logical types for untyped languages. In Proc. International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Mads Tofte and Jean-Pierre Talpin. 1997. Region-based Memory Management. Information and Computation. Google Scholar
Digital Library
- Niki Vazou, Eric L Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton-Jones. 2014. Refinement types for Haskell. In Proc. International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Philip Wadler and Stephen Blott. 1989. How to make ad-hoc polymorphism less ad hoc. In Proc. Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Andrew K Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Information and Computation. Google Scholar
Digital Library
Index Terms
Relational nullable types with Boolean unification
Recommendations
Polymorphic types and effects with Boolean unification
We present a simple, practical, and expressive type and effect system based on Boolean constraints. The effect system extends the Hindley-Milner type system, supports parametric polymorphism, and preserves principal types modulo Boolean equivalence. We ...
Boxy types: inference for higher-rank types and impredicativity
ICFP '06: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programmingLanguages with rich type systems are beginning to employ a blend of type inference and type checking, so that the type inference engine is guided by programmer-supplied type annotations. In this paper we show, for the first time, how to combine the ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...






Comments