Type systems
A type system is a set of rules that assigns types to the expressions of a program, and type theory studies such rules. A static checker applies them before the program runs, and a soundness proof establishes which errors the rules exclude (Cardelli, 1997; Krishnamurthi & Politz, n.d.). In logic, certain type theories represent a proposition as a type and a proof as an expression of that type (Wadler, 2007).
Static checkers can flag some bugs that reached real projects, and experiments find that the effect on development time varies by task (Gao et al., 2017b; Khan et al., 2022; Mayer et al., 2012). Researchers dispute how far static typing is associated with fewer defects across GitHub projects (Ray et al., 2014; Berger et al., 2019b; Ray et al., 2019).
From paradoxes to typed expressions
Types began as a remedy for logical contradictions. Bertrand Russell used them in his 1908 theory to address paradoxes, including that of a greatest ordinal. His ramified theory added extra orders within types, which later work removed on the way to simple type theory (Russell, 1908; Kamareddine et al., 2002).
In 1940, Alonzo Church formulated simple type theory using features of the lambda calculus, a notation for defining and applying functions. Church credited Leon Chwistek and F. P. Ramsey with suggesting a simpler form of Russell’s system (Church, 1940).
What a checker guarantees
A type checker guarantees only what its rules and their proof cover. As an illustration, a rule may require that a function’s argument has the function’s declared input type. Static type checking applies such rules before the program runs; a dynamic check tests a requirement during execution (Cardelli, 1997; Krishnamurthi & Politz, n.d.; Ray et al., 2014).
A sound type system guarantees that accepted programs avoid a specified class of errors. In one approach to proving soundness, each step of running a program preserves its type, and the proof excludes states that would get stuck on a forbidden error. The model determines which failures count and which runtime errors it still permits (Cardelli, 1997; Wright & Felleisen, 1994; Krishnamurthi & Politz, n.d.).
Languages differ in how far they carry such guarantees. For a model of a realistic subset of Rust, RustBelt gives a machine-checked safety proof. By contrast, TypeScript deliberately accepts some uses that can violate its static types. The term “strong typing” is ambiguous: one usage means a sound static type system, another includes detecting type confusion during execution (Jung et al., 2018; Microsoft TypeScript Team, n.d.c; Wright & Felleisen, 1994; Ray et al., 2014).
Reusing code and inferring types
Polymorphism lets an operation work with values of different types. With parametric polymorphism, one implementation is described in terms of a type parameter: an identity function returns its argument unchanged, whether a number or a string (Cardelli & Wegner, 1985). With overloading, one name selects different implementations, as addition does for integers and real numbers. Subtyping permits a value of a more specific type where a broader type is expected (Cardelli & Wegner, 1985; Milner, 1978).
Type inference derives types from code and its uses. The Hindley–Milner tradition asks when a checker can find a principal type, a most general type from which the other valid types follow. Damas and Milner showed this for the part of ML their model covers (Damas & Milner, 1982). In some systems that allow type parameters in more places than ML, complete inference is impossible, and programmers supply annotations to guide it (Peyton Jones et al., 2007).
Static typing in practice
Studies of static typing measure different things: bugs a checker would have flagged, time spent on tasks, defects across projects, or the cost of runtime checks.
Bugs a checker can flag
A checker run on old code would have flagged a minority of the bugs that reached real projects. In a JavaScript study, Flow 0.30, another JavaScript type checker, and TypeScript 2.0 each flagged 15% of the sampled public bugs. The researchers used the eventual fixes to guide where they added annotations, which declare expected types (Gao et al., 2017b).
A study of 210 Python projects estimated that the mypy checker could have flagged 15% of the defects that needed a correction, or 11% of all sampled defects. It often flagged mishandling of null values, which mark the absence of a value. Many defects fixed by changing values or adding or removing code escaped detection (Khan et al., 2022).
What a checker detects depends on the annotations it is given. In a sample of 40 known Python type-related bugs, three checkers together detected 14 before researchers added annotations and 29 afterward (Xu et al., 2023).
Development and maintenance time Weak evidence: few or small studies support this
The effect on development time depends on the task, in a few small experiments. In a 49-person experiment, participants spent about 27 hours each building a parser, and typing made no overall difference. With an undocumented application programming interface (the operations one program offers another), each typing approach sped up some tasks (Hanenberg, 2010; Mayer et al., 2012).
A 33-person experiment found that static typing helped participants understand undocumented code and fix type errors, but not fix errors in what the code does (Hanenberg et al., 2014). A reanalysis found the advantage for identifying unfamiliar classes significant only among participants who started with dynamic typing (Siegmund et al., 2020).
Defects across projects
Researchers disagree on how much of a reported link between static typing and defects survives reanalysis. A 2014 study of 729 GitHub projects across 17 languages reported a modest advantage for static over dynamic typing among functional languages. It estimated larger effects for project size, team size and the size of code changes (Ray et al., 2014).
After correcting the analysis, a reanalysis found four language associations that met its statistical test, each with a very small estimated effect. Revising the language groupings changed the result for two of the five categories (Berger et al., 2019b). The original authors replied that the reanalysis largely reproduced their results, and agreed that effects were small and could be absent. Their 2017 journal version, on 728 projects, kept the direction of the findings; the reanalysis authors said the data they received was the conference version’s (Ray et al., 2019; Ray et al., 2017; Berger et al., 2019a).
Other repository studies use other measures of bugs. A comparison of JavaScript and TypeScript projects found no evidence of a lower share of bug-fix commits or faster bug closure in the TypeScript projects. A study of 600 projects associated static typing with shorter times to resolve bugs, and with fixes that touched more files (Bogner & Merkel, 2022; Zhang et al., 2020a).
Runtime cost of mixing typing styles
Gradual typing lets programmers choose which parts of a program to check statically, and extend checking as they add type information. Typed Scheme showed how a multi-module program can run while only some modules have types (Siek & Taha, 2006; Siek et al., 2015; Tobin-Hochstadt & Felleisen, 2008). In sound gradual typing, the language enforces its static guarantees where checked and unchecked parts interact, and the cost of those checks depends on how they interact (Siek et al., 2015; Greenman et al., 2019).
A mix of checked and unchecked parts can run much more slowly than either endpoint. In a Typed Racket benchmark, the slowest mix of one program took 114.47 times as long as its untyped version, while the fully typed version took 0.99 times as long. To capture this spread, a benchmark can test each mix at a chosen level, such as modules, or sample mixes when there are too many to test (Takikawa et al., 2016; Greenman et al., 2019).
Implementation changes can reduce this overhead. A system that compiles code as it runs removed more than 90% of it on typical benchmarks from earlier Typed Racket work. For Reticulated Python, the standard interpreter took up to six times as long as for equivalent untyped programs. Combining an optimization with PyPy, another Python implementation, left no measured overhead (Bauman et al., 2017; Vitousek et al., 2019).
Propositions as types
The Curry–Howard correspondence relates propositions to types and proofs to typed expressions; simplifying a proof corresponds to evaluating an expression. Martin-Löf’s account of constructive proof, for example, treats a proof of “if A, then B” as a function that turns a proof of A into a proof of B (Wadler, 2007; Martin-Löf, 1984).
The correspondence depends on how proofs are recorded. In one formulation, proofs and terms pair one to one; with extra rules governing the use of assumptions, distinct proofs may share an expression. Girard and Reynolds independently developed System F, which can express functions that take types as parameters; in its logic, a statement can be made about all propositions (Murfet & Troiani, 2026; Wadler, 2007).
Proof assistants
A proof assistant checks a mathematical argument by checking the type of the expression that encodes it. In early Coq, commands called tactics built a proof expression, and the checker then checked the whole expression. Its Calculus of Constructions had been influenced by System F and by Automath, a system for checking mathematical material (Coquand et al., 2015; Coquand & Huet, 1988; Geuvers & Nederpelt, 2022).
Coq checked a formal proof of the four-colour theorem. Lean began in 2013 as an interactive theorem prover based on the Calculus of Inductive Constructions, the extension of the calculus that Coq implemented (Gonthier, n.d.; Coquand et al., 2015; de Moura & Ullrich, 2021).
What else types can express
Dependent types let a type refer to a value: in Agda, the length of a vector can be part of its type, so a function’s input type can distinguish vectors of different lengths (Agda developers, n.d.).
Linear types specify how values are used. In Linear Haskell, if code consumes the result of a linear function exactly once, the function consumes its argument exactly once (Bernardy et al., 2018).
Homotopy type theory connects type theory with homotopy theory, the study of spaces up to continuous deformation. Its univalence axiom allows structures with the same form, in a precise mathematical sense, to be identified (The Univalent Foundations Program, 2013).
Further reading
- Cardelli defines type soundness relative to the errors a language forbids (Cardelli, 1997).
- Wadler develops the correspondence between propositions, types and proofs across different formal systems (Wadler, 2007).
- Gao and colleagues estimate detectable bugs by adding types to historical versions of JavaScript programs (Gao et al., 2017b).
- Berger and colleagues show how rerunning and correcting the GitHub analysis changed its results (Berger et al., 2019b).
- Greenman and colleagues describe how to measure costs across mixes of typed and untyped code (Greenman et al., 2019).
First published .
Known gaps
What this article cannot tell you yet.
- The debate over type theory and set theory as foundations for mathematics remains outside the scope of this article.
- Coverage of homotopy type theory focuses on univalence. It leaves open how practitioners use the framework in formal mathematics.
- The controlled experiments on development time cover specific programming tasks. Long-term effects across teams and projects are outside their scope.
- The historical detection rates apply to sampled defects, checker versions and annotation procedures. They leave open how many defects teams would prevent in ordinary development.
References
- Solid source
- Rated highly trustworthy by the research, and every passage taken from it was found in it.
- Weak source
- Rated low, or a passage taken from it was not found in it.
- Medium trust
- Rated medium by the research.
- Not checked
- Rated high, but its passages could not all be checked against it.
Show all 44 references
- Agda developers (n.d.). What is Agda? Agda 2.6.0 documentation. https://agda.readthedocs.io/en/v2.6.0/getting-started/what-is-agda.html Solid source Documentation, read in large part.
- Bauman, S., Bolz-Tereick, C. F., Siek, J., & Tobin-Hochstadt, S. (2017). Sound gradual typing: Only mostly dead. Proceedings of the ACM on Programming Languages. https://scholarworks.iu.edu/dspace/items/131d8f23-1943-45ae-86c3-28a6a526f0e0 Solid source Peer-reviewed, abstract only.
- Berger, E. D., Hollenbeck, C., Maj, P., Vitek, O., & Vitek, J. (2019b). On the impact of programming languages on code quality: A reproduction study. ACM Transactions on Programming Languages and Systems. https://arxiv.org/abs/1901.10220 Solid source Peer-reviewed, read in large part.
- Berger, E. D., Maj, P., Vitek, O., & Vitek, J. (2019a). FSE/CACM rebuttal²: Correcting a large-scale study of programming languages and code quality in GitHub. arXiv. https://arxiv.org/abs/1911.11894 Medium trust Preprint, read in large part.
- Bernardy, J., Boespflug, M., Newton, R. R., Peyton Jones, S., & Spiwack, A. (2018). Linear Haskell: Practical Linearity in a Higher-Order Polymorphic Language. Proceedings of the ACM on Programming Languages. https://arxiv.org/pdf/1710.09756 Solid source Peer-reviewed, read in large part.
- Bogner, J., & Merkel, M. (2022). To type or not to type? A systematic comparison of the software quality of JavaScript and TypeScript applications on GitHub. Proceedings of the 19th International Conference on Mining Software Repositories. https://arxiv.org/abs/2203.11115 Solid source Peer-reviewed, read in large part.
- Cardelli, L., & Wegner, P. (1985). On Understanding Types, Data Abstraction, and Polymorphism. ACM Computing Surveys. https://www.windley.com/docs/cardelli85understanding.pdf Medium trust Peer-reviewed, read in large part.
- Cardelli, L. (1997). Type systems. The Computer Science and Engineering Handbook, CRC Press. https://web.eecs.umich.edu/~weimerw/590/reading/Cardelli_TypeSystems.pdf Medium trust Peer-reviewed, read in large part.
- Church, A. (1940). A Formulation of the Simple Theory of Types. The Journal of Symbolic Logic, 5(2), 56–68. https://www.cip.ifi.lmu.de/~langeh/test/1940%20-%20Church%20-%20A%20Formulation%20of%20the%20Simple%20Theory%20of%20Types_cropped.pdf Solid source Peer-reviewed, read in full.
- Coquand, T., & Huet, G. (1988). The Calculus of Constructions. Information and Computation, 76, 95–120. https://courses.grainger.illinois.edu/cs522/sp2016/TheCalculusOfConstructions.pdf Solid source Peer-reviewed, read in full.
- Coquand, T., Huet, G., & Paulin-Mohring, C. (2015). Early history of Coq. Coq 8.18+rc1 documentation. https://rocq-prover.org/doc/V8.18%2Brc1/refman/history.html Solid source Documentation, read in full.
- Damas, L., & Milner, R. (1982). Principal type-schemes for functional programs. Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. https://www.cs.cmu.edu/afs/cs/user/crary/www/819-f09/DamasMilner82.pdf Solid source Peer-reviewed, read in large part.
- Geuvers, H., & Nederpelt, R. (2022). Characteristics of de Bruijn's early proof checker Automath. arXiv. https://arxiv.org/abs/2203.01173v1 Medium trust Peer-reviewed, abstract only.
- de Moura, L., & Ullrich, S. (2021). The Lean 4 Theorem Prover and Programming Language (System Description). Automated Deduction – CADE 28. https://lean-lang.org/papers/lean4.pdf Solid source Read in full.
- Gao, Z., Bird, C., & Barr, E. T. (2017b). To type or not to type: Quantifying detectable bugs in JavaScript. Proceedings of the 39th International Conference on Software Engineering. https://swizec.com/pdfs/typestudy.pdf Solid source Peer-reviewed, read in large part.
- Gonthier, G. (n.d.). A computer-checked proof of the Four Colour Theorem. Microsoft Research Cambridge. https://www.cl.cam.ac.uk/~lp15/Pages/4colproof.pdf Solid source Read in full.
- Greenman, B., Takikawa, A., New, M. S., Feltey, D., Findler, R. B., Vitek, J., et al. (2019). How to evaluate the performance of gradual type systems. Journal of Functional Programming. https://www.cambridge.org/core/services/aop-cambridge-core/content/view/DC765724C52A3A462F16C7FB3AD18697/S0956796818000217a.pdf/how-to-evaluate-the-performance-of-gradual-type-systems.pdf Medium trust Peer-reviewed, read in large part.
- Hanenberg, S. (2010). An experiment about static and dynamic type systems: Doubts about the positive impact of static type systems on development time. Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications. https://ics.uci.edu/~jajones/INF102-S18/readings/23_hanenberg.pdf Solid source Peer-reviewed, read in large part.
- Hanenberg, S., Kleinschmager, S., Robbes, R., Tanter, É., & Stefik, A. (2014). An empirical study on the impact of static typing on software maintainability. Empirical Software Engineering. https://pleiad.cl/papers/2014/hanenbergAl-emse2014.pdf Medium trust Peer-reviewed, read in large part.
- Jung, R., Jourdan, J., Krebbers, R., & Dreyer, D. (2018). RustBelt: Securing the Foundations of the Rust Programming Language. Proceedings of the ACM on Programming Languages. https://www.mpi-sws.org/~dreyer/papers/rustbelt/paper.pdf Solid source Peer-reviewed, read in large part.
- Kamareddine, F., Laan, T., & Nederpelt, R. (2002). Types in Logic and Mathematics Before 1940. The Bulletin of Symbolic Logic, 8(2). https://citeseerx.ist.psu.edu/document?doi=a33a2952322ce833068b2b40963f7898e14a0e31&repid=rep1&type=pdf Solid source Peer-reviewed, read in full.
- Khan, F., Chen, B., Varro, D., & McIntosh, S. (2022). An Empirical Study of Type-Related Defects in Python Projects. IEEE Transactions on Software Engineering. https://rebels.cs.uwaterloo.ca/papers/tse2021_khan.pdf Solid source Peer-reviewed, read in large part.
- Krishnamurthi, S., & Politz, J. G. (n.d.). Programming and programming languages. Brown University. https://cs.brown.edu/people/sk/tmp/PAPL-jan-2016/ Medium trust Book, read in large part.
- Martin-Löf, P. (1984). Intuitionistic Type Theory. Bibliopolis. https://archive-pml.github.io/martin-lof/pdfs/Bibliopolis-Book-retypeset-1984.pdf Solid source Book, read in full.
- Mayer, C., Hanenberg, S., Robbes, R., Tanter, É., & Stefik, A. (2012). An empirical study of the influence of static type systems on the usability of undocumented software. Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications. https://www.researchgate.net/publication/262317340_An_empirical_study_of_the_influence_of_static_type_systems_on_the_usability_of_undocumented_software Solid source Peer-reviewed, read in large part.
- Milner, R. (1978). A Theory of Type Polymorphism in Programming. Journal of Computer and System Sciences. https://www.cs.tufts.edu/comp/150FP/archive/robin-milner/type-polymorphism.pdf Solid source Peer-reviewed, read in large part.
- Murfet, D., & Troiani, W. A. (2026). Gentzen–Mints–Zucker duality. Mathematical Structures in Computer Science, 36, e7. https://www.cambridge.org/core/journals/mathematical-structures-in-computer-science/article/gentzenmintszucker-duality/7C3940A71443083C67F05A9B9FFFC155 Solid source Peer-reviewed, read in large part.
- Peyton Jones, S., Vytiniotis, D., Weirich, S., & Shields, M. (2007). Practical type inference for arbitrary-rank types. Journal of Functional Programming. https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/putting.pdf Solid source Peer-reviewed, read in large part.
- Ray, B., Posnett, D., Filkov, V., & Devanbu, P. (2014). A large scale study of programming languages and code quality in GitHub. Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering. https://web.cs.ucdavis.edu/~filkov/papers/lang_github.pdf Solid source Peer-reviewed, read in large part.
- Ray, B., Posnett, D., Filkov, V., & Devanbu, P. (2017). A large-scale study of programming languages and code quality in GitHub. Communications of the ACM. https://baishakhir.github.io/uploads/cacm2017-lang.pdf Solid source Peer-reviewed, read in large part.
- Ray, B., Devanbu, P. T., & Filkov, V. (2019). Rebuttal to berger et al., TOPLAS 2019. arXiv. https://arxiv.org/abs/1911.07393 Medium trust Preprint, abstract only.
- Russell, B. (1908). Mathematical Logic as Based on the Theory of Types. American Journal of Mathematics, 30(3), 222–262. https://authortomharper.com/wp-content/uploads/2022/04/1908-Mathematical-Logic-as-Based-on-the-Theory-of-Types-Russell.pdf Solid source Peer-reviewed, read in full.
- Siegmund, J., Peitek, N., Apel, S., & Siegmund, N. (2020). Mastering variation in human studies: The role of aggregation. ACM Transactions on Software Engineering and Methodology. https://www.se.cs.uni-saarland.de/publications/docs/SPA%2B20.pdf Solid source Peer-reviewed, read in full.
- Siek, J. G., & Taha, W. (2006). Gradual Typing for Functional Languages. Scheme and Functional Programming Workshop. https://web.stanford.edu/class/cs242/materials/old/siek06__gradual.pdf Solid source Peer-reviewed, read in large part.
- Siek, J. G., Vitousek, M. M., Cimini, M., & Boyland, J. T. (2015). Refined criteria for gradual typing. 1st Summit on Advances in Programming Languages, Schloss Dagstuhl – Leibniz-Zentrum für Informatik. https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.SNAPL.2015.274 Medium trust Peer-reviewed, abstract only.
- Takikawa, A., Feltey, D., Greenman, B., New, M. S., Vitek, J., & Felleisen, M. (2016). Is sound gradual typing dead? Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. https://www2.ccs.neu.edu/racket/pubs/popl16-tfgnvf.pdf Solid source Peer-reviewed, read in large part.
- Tobin-Hochstadt, S., & Felleisen, M. (2008). The Design and Implementation of Typed Scheme. 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. https://www2.ccs.neu.edu/racket/pubs/popl08-thf.pdf Medium trust Peer-reviewed, read in large part.
- Microsoft TypeScript Team (n.d.c). Type compatibility. TypeScript Handbook. https://www.typescriptlang.org/docs/handbook/type-compatibility.html Solid source Documentation, read in large part.
- The Univalent Foundations Program (2013). Homotopy Type Theory: Univalent Foundations of Mathematics. arXiv. https://arxiv.org/abs/1308.0729 Medium trust Preprint, abstract only.
- Vitousek, M. M., Siek, J. G., & Chaudhuri, A. (2019). Optimizing and evaluating transient gradual typing. Proceedings of the ACM on Programming Languages. https://arxiv.org/abs/1902.07808 Solid source Preprint, read in large part.
- Wadler, P. (2007). The Girard–Reynolds Isomorphism (Second Edition). Theoretical Computer Science, 375(1–3), 201–226. https://homepages.inf.ed.ac.uk/wadler/papers/gr2/gr2-tcs.pdf Solid source Peer-reviewed, read in full.
- Wright, A. K., & Felleisen, M. (1994). A Syntactic Approach to Type Soundness. Information and Computation. https://courses.grainger.illinois.edu/cs522/sp2016/ASyntacticApproachToTypeSoundness.pdf Solid source Peer-reviewed, read in large part.
- Xu, W., Chen, L., Su, C., Guo, Y., Li, Y., Zhou, Y., et al. (2023). How well static type checkers work with gradual typing? A case study on Python. IEEE/ACM International Conference on Program Comprehension. https://conf.researchr.org/details/icpc-2023/icpc-2023-research/8/How-Well-Static-Type-Checkers-Work-with-Gradual-Typing-A-Case-Study-on-Python Medium trust Peer-reviewed, abstract only.
- Zhang, J. M., Li, F., Hao, D., Wang, M., Tang, H., Zhang, L., et al. (2020a). A study of bug resolution characteristics in popular programming languages. IEEE Transactions on Software Engineering. https://arxiv.org/abs/1801.01025 Solid source Peer-reviewed, read in large part.