Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Typing rule
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Notation == Typing rules specify the structure of a ''typing [[Relation (mathematics)|relation]]'' that relates syntactic terms to their types.<ref name="TAPL" />{{rp|92}} Syntactically, the typing relation is usually denoted by a colon, so for example <math>e:\tau</math> denotes that an expression <math>e</math> has type <math>\tau</math>. The rules themselves are usually specified using the notation of [[natural deduction]].<ref name="TAPL" />{{rp|26}} For example, the following typing rules specify the typing relation for a simple language of [[Boolean data type|booleans]]:<ref name="TAPL" />{{rp|93}} :<math> \frac{}{\mathsf{true} : \mathsf{Bool}} \qquad \frac{}{\mathsf{false} : \mathsf{Bool}} \qquad \frac{e_1 : \mathsf{Bool} \quad \; e_2 : \tau \quad \; e_3 : \tau}{\mathbf{if}\ e_1\ \mathbf{then}\ e_2\ \mathbf{else}\ e_3 : \tau} </math> 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 (computer science)|variable]] depends on where it is [[bound variable|bound]], which necessitates context-sensitive typing rules. These rules are given by a ''typing [[Judgment (mathematical logic)|judgment]]'', usually written <math>\Gamma \vdash e : \tau</math>, which states that an expression <math>e</math> has type <math>\tau</math> under a [[typing context]] <math>\Gamma</math> that relates variables to their types. Typing contexts are occasionally supplemented by the types of individual variables; for example, <math>\Gamma,x{:}\tau_1 \vdash e : \tau_2</math> can be read as "the context <math>\Gamma</math> supplemented by the information that the expression <math>x</math> has type <math>\tau_1</math> yields the judgement that expression <math>e</math> has type <math>\tau_2</math>". This notation can be used to give typing rules for variable references and lambda abstraction in the [[simply typed lambda calculus]]:<ref name="TAPL" />{{rp|pages=101–102}} :<math> \frac{x{:}\tau \in \Gamma}{\Gamma \vdash x : \tau} \qquad \frac{\Gamma,x{:}\tau_1 \vdash e : \tau_2}{\Gamma \vdash (\lambda x{:}\tau_1.\,e) : \tau_1 \rightarrow \tau_2} </math> Similarly, the following typing rule describes the <math>\mathbf{let}</math> construct of [[Standard ML]]: :<math> \frac{\Gamma \vdash e_1 : \tau_1 \qquad \Gamma, x{:}\tau_1 \vdash e_2 : \tau_2}{ \Gamma \vdash \mathbf{let}\ x = e_1\ \mathbf{in}\ e_2\ \mathbf{end} : \tau_2} </math> Not all systems of typing rules directly specify a [[type checking]] algorithm. For example, the typing rule for applying a [[parametric polymorphism|parametrically polymorphic]] function in the [[Hindley–Milner type system]] requires "guessing" the appropriate type at which the function should be instantiated.<ref>{{cite book |last1=Clément |first1=Dominique |last2=Despeyroux |first2=Thierry |last3=Kahn |first3=Gilles |last4=Despeyroux |first4=Joëlle |title=Proceedings of the 1986 ACM conference on LISP and functional programming - LFP '86 |chapter=A simple applicative language: Mini-ML |date=8 August 1986 |pages=13–27 |doi=10.1145/319838.319847 |chapter-url=https://dl.acm.org/doi/10.1145/319838.319847 |publisher=Association for Computing Machinery|isbn=0897912004 |s2cid=5126579 |url=https://hal.inria.fr/inria-00076025/file/RR-0529.pdf }}</ref> Adapting a declarative rule system to a [[Decidability (logic)|decidable]] algorithm requires the production of a separate, algorithmic system that can be proven to specify the same typing relation.<ref>{{cite journal |last1=Dunfield |first1=Jana |last2=Krishnaswami |first2=Neel |title=Bidirectional Typing |journal=ACM Computing Surveys |date=23 May 2021 |volume=54 |issue=5 |page=98:19 |doi=10.1145/3450952 |s2cid=201058734 |issn=0360-0300|doi-access=free |arxiv=1908.05839 }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)