Neha Patil (Editor)

Type rule

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In type theory, a type 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 type rules is in defining type inference in the simply typed lambda calculus, which is the internal language of Cartesian closed categories.

Notation

An expression e of type τ is written as e : τ . The typing environment is written as Γ . The notation for inference is the usual one for sequents and inference rules, and has the following general form

Γ 1 e 1 : τ 1 Γ n e n : τ n Γ e : τ

The sequents above the line are the premises that must be fulfilled for the rule to be applied, yielding the conclusion: the sequents below the line. This can be read as: if expression e i has type τ i in environment Γ i , for all i = 1.. n , then the expression e will have an environment Γ and type τ .

For example, a simple language to perform arithmetic calculations on real numbers may have the following rules

Γ e 1 : r e a l Γ e 2 : r e a l Γ e 1 + e 2 : r e a l Γ e 1 : i n t e g e r Γ e 2 : i n t e g e r Γ e 1 + e 2 : i n t e g e r

A type rule may have no premises, and usually the line is omitted in these cases. A type rule may also change an environment by adding new variables to a previous environment; for example, a declaration may have the following type rule, where a new variable i d , with type τ , is added to Γ :

Γ e : τ Γ , i d : τ e : τ Γ let id =  e  in  e  end : τ

Here the syntax of the let expression is that of Standard ML. Thus type rules can be used to derive the types of composed expressions, much like in natural deduction.

References

Type rule Wikipedia