Typing Rule
   HOME

TheInfoList



OR:

In
type theory In mathematics and theoretical computer science, a type theory is the formal presentation of a specific type system. Type theory is the academic study of type systems. Some type theories serve as alternatives to set theory as a foundation of ...
, a typing rule is an inference rule that describes how a type system assigns a type to a syntactic construction. These rules may be applied by the type system to determine if a program is well-typed and what type expressions have. A prototypical example of the use of typing rules is in defining type inference in the simply typed lambda calculus, which is the internal language of Cartesian closed categories.


Notation

Typing rules specify the structure of a ''typing relation'' that relates syntactic terms to their types. Syntactically, the typing relation is usually denoted by a colon, so for example e:\tau denotes that an expression e has type \tau. The rules themselves are usually specified using the notation of natural deduction. For example, the following typing rules specify the typing relation for a simple language of booleans: : \frac \qquad \frac \qquad \frac Each rule states that the conclusion below the line may be derived from the premises above the line. The first two rules have no premises above the line, so they are axioms. The third rule has premises above the line (specifically, three premises), so it is an inference rule. In programming languages, the type of a variable depends on where it is bound, which necessitates context-sensitive typing rules. These rules are given by a ''typing judgment'', usually written \Gamma \vdash e : \tau, which states that an expression e has type \tau under a typing context \Gamma that relates variables to their types. Typing contexts are occasionally supplemented by the types of individual variables; for example, \Gamma,x\tau_1 \vdash e : \tau_2 can be read as "the context \Gamma supplemented by the information that the expression x has type \tau_1 yields the judgement that expression e has type \tau_2". This notation can be used to give typing rules for variable references and lambda abstraction in the simply typed lambda calculus: : \frac \qquad \frac Similarly, the following typing rule describes the \mathbf construct of
Standard ML Standard ML (SML) is a General-purpose programming language, general-purpose, High-level programming language, high-level, Modular programming, modular, Functional programming, functional programming language with compile-time type checking and t ...
: : \frac Not all systems of typing rules directly specify a type checking algorithm. For example, the typing rule for applying a parametrically polymorphic function in the Hindley–Milner type system requires "guessing" the appropriate type at which the function should be instantiated. Adapting a declarative rule system to a decidable algorithm requires the production of a separate, algorithmic system that can be proven to specify the same typing relation.


See also

*
Judgment (mathematical logic) In mathematical logic, a judgment (or judgement) or assertion is a statement or enunciation in a metalanguage. For example, typical judgments in first-order logic would be ''that a string is a well-formed formula'', or ''that a proposition is t ...
* Type system *
Type theory In mathematics and theoretical computer science, a type theory is the formal presentation of a specific type system. Type theory is the academic study of type systems. Some type theories serve as alternatives to set theory as a foundation of ...
* Curry–Howard correspondence * Sequent calculus


References


Further reading

* * Cardelli, Luca (June 2004)
Type Systems
41 pages. Computer Science Handbook, 2nd Edition, Ch. 97. Edited by Allen B. Tucker. ISBN 9780429209390. Retrieved 5 January 2025. {{type-theory-stub Data types Program analysis Type theory