Type inference
We will give the rules for type assignment. These rules are parameterized
by a set Specials of Symbols, a set Axioms of pairs
consisting of a Symbol and a special Symbol,
a set PiRules of triples of special Symbols
and a set SigmaRules of triples of special Symbols.
The special symbols, their axioms and rules determine the set of
typable expressions.
Let
- A be a Context,
- x a Symbol,
- i an Integer,
- s, s1, s2, s3 special Symbols,
and
-
a, b, c, d instances of Math.
a has type b in A is denoted by A |- a:b.
The empty context is denoted by \epsilon.
A mathematical expression
a is meaningful in a context A if it can be typed in A,
thus \exists b. A |- a:b.
\table
(function type) \= \frac{\mbox{\scriptsize \em Context}(\Gamma,
\mbox{\scriptsize \em Declaration}(x,t)) |- u:v \hspace{2mm}
\Gamma |- \mbox{\scriptsize \em FunctionType}
(x,\mbox{\scriptsize \em domain}=t,\mbox{\scriptsize \em range}=v):s}
{\Gamma |- \mbox{\scriptsize \em Abstraction}
(x,\mbox{\scriptsize \em domain}=t,\mbox{\scriptsize \em body}=u):
\mbox{\scriptsize \em FunctionType}
(x,\mbox{\scriptsize \em domain}=t,\mbox{\scriptsize \em range}=v)}\=
x\kill
{\small (axiom)} \>{\scriptsize \epsilon |- s1:s2}
\> if (s1,s2) \in Axioms
{\small (declaration)} \> \frac{A |- a:s}
{A,\mbox{\scriptsize Declaration(subject=}x,
\mbox{\scriptsize type=}a) |- x:a}
\> if x \not\in A
{\small (definition)} \> \frac{A |- a:b}
{A,\mbox{\scriptsize Definition(subject=}x,
\mbox{\scriptsize body=}a,
\mbox{\scriptsize type=}b) |- x:b}
\> if x \not\in A
{\small (int)} \>{\scriptsize \epsilon |- i:int}
{\small (application)} \>
\frac{A |- a:\mbox{\scriptsize PiType(local=}x,
\mbox{\scriptsize domain=}b,\mbox{\scriptsize range=}c)
\hspace{2mm} A |- d:b}
{A |- \mbox{\scriptsize Application(function=}a,
\mbox{\scriptsize argument=}d): c[x:=d]}
{\small (abstraction)} \>
\frac{A, \mbox{\scriptsize Declaration(subject=}x,
\mbox{\scriptsize type=}a) |- b:c \hspace{2mm}
A |- \mbox{\scriptsize PiType(local=}x,
\mbox{\scriptsize domain=}a,\mbox{\scriptsize range=}c):s}
{A |- \mbox{\scriptsize Abstraction(local=}x
\mbox{\scriptsize domain}=a,\mbox{\scriptsize body=}b):
\mbox{\scriptsize PiType(local=}x,
\mbox{\scriptsize domain=}a,\mbox{\scriptsize range}=c)}
{\small (pitype)} \>
\frac{A |- a:s1 \hspace{2mm}
A, \mbox{\scriptsize Declaration(local=}x,
\mbox{\scriptsize type=} a) |- b:s2}
{A |- \mbox{\scriptsize PiType(local=}x,
\mbox{\scriptsize domain}=a,\mbox{\scriptsize range=}b):s3}
\> if (s1,s2,s3) \in PiRules
{\small (fst)} \>
\frac{A |- a:\mbox{\scriptsize SigmaType(local=}x,
\mbox{\scriptsize fsttype=}b,\mbox{\scriptsize sndtype=}c)}
{A |- \mbox{\scriptsize Fst(pair=}a):b}
{\small (snd)} \>
\frac{A |- a:\mbox{\scriptsize SigmaType(local=}x,
\mbox{\scriptsize fsttype=}b,\mbox{\scriptsize sndtype=}c)}
{A |- \mbox{\scriptsize Snd(pair=}a):c[x:=\mbox{\scriptsize Fst(}a)]}
{\small (pair)} \>
\frac{A |- a:b \hspace{2mm} A |- c:d[x:=a] \hspace{2mm}
A |- \mbox{\scriptsize SigmaType(local=}x,
\mbox{\scriptsize fsttype=}b,\mbox{\scriptsize sndtype=}d):s}
{A |- \mbox{\scriptsize Pair(local=}x,
\mbox{\scriptsize fst}=a,\mbox{\scriptsize snd=}c,
\mbox{\scriptsize sndtype=}d):
\mbox{\scriptsize SigmaType(local=}x,
\mbox{\scriptsize fsttype=}b,\mbox{\scriptsize sndtype}=d)}
{\small (sigmatype)} \>
\frac{A |- a:s1 \hspace{2mm}
A, \mbox{\scriptsize Declaration(local=}x,
\mbox{\scriptsize type=} a) |- b:s2}
{A |- \mbox{\scriptsize SigmaType(local=}x,
\mbox{\scriptsize fsttype}=a,\mbox{\scriptsize sndtype=}b):s3}
\> if (s1,s2,s3)
\in SigmaRules
{\small (decl-weak)} \>
\frac{A |- a:b
\hspace{2mm} A |- c:s}
{A, \mbox{\scriptsize Declaration(subject=}x,
\mbox{\scriptsize type=}c) |- a:b}
\> if x \not\in A
{\small (def-weak)} \>
\frac{A |- a:b
\hspace{2mm} A |- c:d}
{A, \mbox{\scriptsize Definition(subject=}x,
\mbox{\scriptsize body=}c, \mbox{\scriptsize type=}d) |- a:b}
\> if x \not\in A
{\small (reduction)} \>
\frac{A |- a:b \hspace{2mm} A |- c:s
\hspace{2mm} b \rightarrow c \vee c \rightarrow b}
{A |- a:c}
{\small (unfolding)} \>
\frac{A |- a:b \hspace{2mm} A |- c:s
\hspace{2mm} (A |- b \rightarrow c) \vee (A |- c \rightarrow b)}
{A |- a:c}
<\table>