|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| 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 [[Computer program|program]] is well typed and what type [[Expression (computer science)|expression]]s 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]].
| | Hello, I'm Hilda, a 27 year old from Clermont, Belgium.<br>My hobbies include (but are not limited to) Target Shooting, Amateur geology and watching Breaking Bad.<br><br>Here is my homepage: [http://www.travailadomicile2014.sitew.fr travail à domicile] |
| | |
| == Notation ==
| |
| <!-- historical reference (what it the paper by Luca Cardelli that introduce this notation?) -->
| |
| An expression <math>e</math> of type <math>\tau</math> is written as <math>e\!:\!\tau</math>. The [[typing environment]] is written as <math>\Gamma</math>. The notation for inference is the usual one for [[sequent]]s and [[inference rule]]s, and has the following general form
| |
| | |
| :<math>
| |
| \frac{\Gamma_1 \vdash e_1\!:\!\tau_1 \quad \cdots \quad \Gamma_n \vdash e_n\!:\!\tau_n}{\Gamma \vdash e\!:\!\tau}
| |
| </math>
| |
| | |
| 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 <math>e_i</math> has type <math>\tau_i</math> in [[Typing environment|environment]] <math>\Gamma_i</math>, for all <math>i=1..n</math>, then the expression <math>e</math> will have an environment <math>\Gamma</math> and type <math>\tau</math>''.
| |
| | |
| For example, a simple language to perform arithmetic calculations on real numbers may have the following rules
| |
| | |
| :<math>
| |
| \frac{\Gamma \vdash e_1\!:\!real \quad \Gamma \vdash e_2\!:\!real}{\Gamma \vdash e_1+e_2\!:\!real}
| |
| \qquad \frac{\Gamma \vdash e_1\!:\!integer \quad \Gamma \vdash e_2 : integer}{\Gamma \vdash e_1+e_2\!:\!integer} \qquad \cdots
| |
| </math>
| |
| | |
| 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 <math>id</math>,
| |
| with type <math>\tau'</math>, is added to <math>\Gamma</math>:
| |
| | |
| :<math>
| |
| \frac{\Gamma \vdash e'\!:\!\tau' \quad \Gamma, id\!:\!\tau' \vdash e\!:\!\tau}{\Gamma \vdash \text{let id = } e' \text{ in } e \text{ end} :\!\tau}
| |
| </math>
| |
| | |
| This types can be used to derive composed expressions types, much like in [[natural deduction]].
| |
| | |
| ==See also==
| |
| * [[Judgment (mathematical logic)]]
| |
| * [[Type system]]
| |
| * [[Type theory]]
| |
| * [[Curry–Howard correspondence]]
| |
| | |
| == Further reading ==
| |
| * Luca Cardelli, "Type Systems", ''ACM Computing Surveys''
| |
| | |
| {{type-theory-stub}}
| |
| | |
| [[Category:Data types]]
| |
| [[Category:Program analysis]]
| |
| [[Category:Type theory]]
| |
Hello, I'm Hilda, a 27 year old from Clermont, Belgium.
My hobbies include (but are not limited to) Target Shooting, Amateur geology and watching Breaking Bad.
Here is my homepage: travail à domicile