It also ensures that the binary relation $\vartriangleright
\,\subseteq\!\types^{2}$ defined by $t_1\lor t_2\vartriangleright
t_i$, $t_1\land t_2\vartriangleright
t_i$, $\neg t \vartriangleright t$ is Noetherian.
t_i$, $\neg t \vartriangleright t$ is Noetherian.\footnote{In a nutshell, we can do proofs of induction on the structure of unions and negations---and, thus, intersections---but arrows, products, and basic types are the base cases for the induction.}
This gives an induction principle on $\types$ that we
will use without any further explicit reference to the relation.
We refer to $ b $, $\times$, and $\to$ as \emph{type constructors}
...
...
@@ -46,7 +46,7 @@ Section~\ref{sec:syntax} right below) that have that type, and that subtyping is
containment (\emph{ie}, a type $s$ is a subtype of a type $t$ if and only if $t$
contains all the values of type $s$). In particular, $s\to t$
contains all $\lambda$-abstractions that when applied to a value of
type $s$, if the computation terminates, then they return a result of
type $s$, if their computation terminates, then they return a result of
type $t$ (\emph{eg}, $\Empty\to\Any$ is the set of all
functions\footnote{\label{allfunctions}Actually, for every type $t$,
all types of the form $\Empty{\to}t$ are equivalent and each of them
...
...
@@ -80,8 +80,8 @@ intuitively, $\lambda^{\wedge_{i\in I}s_i\to t_i} x.e$ is a well-typed
value if for all $i{\in} I$ the hypothesis that $x$ is of type $s_i$
implies that the body $e$ has type $t_i$, that is to say, it is well
typed if $\lambda^{\wedge_{i\in I}s_i\to t_i} x.e$ has type $s_i\to
t_i$ for all $i\in I$. Every value is associated to a type: we
described above the types of constants and abstractions and, inductively,
t_i$ for all $i\in I$. Every value is associated to a type: the type of $c$ is $\basic c$; the type of
$\lambda^{\wedge_{i\in I}s_i\to t_i} x.e$ is $\wedge_{i\in I}s_i\to t_i$; and, inductively,
the type of a pair of values is the product of the types of the
values.
...
...
@@ -100,7 +100,7 @@ The dynamic semantics is defined as a classic left-to-right cbv reduction for a
\]
The semantics of type-cases uses the relation $v\in t$ that we
informally defined in the previous section. We delay its formal
definition to Section~\ref{sec:type-schemes}. Context reductions are
definition to Section~\ref{sec:type-schemes} (it deals with some corner cases for functional values). Context reductions are
We introduce the new syntactic category of \emph{types schemes} which are the terms $\ts$ produced by the following grammar.
We introduce the new syntactic category of \emph{types schemes} which are the terms $\ts$inductively produced by the following grammar.
\[
\begin{array}{lrcl}
\textbf{Type schemes}&\ts& ::=& t \alt\tsfun{\arrow t t ; \cdots ; \arrow t t}\alt\ts\tstimes\ts\alt\ts\tsor\ts\alt\tsempty
...
...
@@ -504,7 +509,7 @@ Note that $\tsint \ts$ is closed under subsumption and intersection
empty set of types is different from $\Empty$ whose interpretation is
the set of all types.
\begin{lemma}
\begin{lemma}[\cite{Frisch2008}]
Let $\ts$ be a type scheme and $t$ a type. It is possible to decide the assertion $t \in\tsint\ts$,
which we also write $\ts\leq t$.
\end{lemma}
...
...
@@ -520,7 +525,7 @@ the value. By induction on the definition of values: $\tyof c {} =
v{}\leq t$.
We also need to perform intersections of type schemes so as to intersect the static type of an expression (\emph{ie}, the one deduced by conventional rules) with the one deduced by occurrence typing (\emph{ie}, the one derived by $\vdashp$). For our algorithmic system (see \Rule{Env$_{\scriptscriptstyle\mathcal{A}}$} in Section~\ref{sec:algorules}) all we need to define is the intersection of a type scheme with a type:
\begin{lemma}
\begin{lemma}[\cite{Frisch2008}]
Let $\ts$ be a type scheme and $t$ a type. We can compute a type scheme, written $t \tsand\ts$, such that
\(\tsint{t \tsand\ts}=\{s \alt\exists t' \in\tsint\ts.\ t \land t' \leq s \}\)
\subsubsection{Operators for type constructors}\label{sec:typeops}
{}\beppe{The explaination that follows is redundant in Section~\ref{sec:ideas}. Harmonize!}
{}\beppe{The explaination that follows is redundant with Section~\ref{sec:ideas}. Harmonize!}
In order to define the algorithmic typing of expressions like
applications and projections we need to define the operator on
applications and projections we need to define the operators on
types we used in Section~\ref{sec:ideas}. Consider the rule \Rule{App} for applications. It essentially
does three things: $(1)$ it checks that the function has functional
type; $(2)$ it checks that the argument is in the domain of the
...
...
@@ -565,7 +570,7 @@ union of intersection of arrows and negations of types. Checking that
the function has a functional type is easy since it corresponds to
checking that it has a type subtype of $\Empty\to\Any$. Determining
its domain and the type of the application is more complicated. For
instance if we have a function of type \code{\(t=(\Int\to\Int)\)\(\wedge\)\((\Bool\to\Bool)\)}, which
instance, imagine we have a function of type \code{\(t=(\Int\to\Int)\)\(\wedge\)\((\Bool\to\Bool)\)}, which
denotes functions that will return an integer if applied to an integer,
and will return a Boolean if applied to a Boolean.
It is possible to compute the domain of such a type
...
...
@@ -581,13 +586,13 @@ an application of a function of type \(t_1\) to an argument of
type \(t_2\).
In the example with \code{\(t=(\Int\to\Int)\)\(\wedge\)\((\Bool\to\Bool)\)}, it gives \code{\( t \circ\Int=\Int\)},
\code{\( t \circ\Bool=\Bool\)}, and
\code{\( t \circ(\Int\vee\Bool)=\Int\vee\Bool\)}. In summary, given a functional type $t$ (\emph{ie}, a type $t$ such that $t\leq\Empty\to\Any$) our algorithms we use the following three operators
\code{\( t \circ(\Int\vee\Bool)=\Int\vee\Bool\)}. In summary, given a functional type $t$ (\emph{ie}, a type $t$ such that $t\leq\Empty\to\Any$) our algorithms will use the following three operators
\begin{eqnarray}
\dom t & = &\max\{ u \alt t\leq u\to\Any\}
\\
\apply t s & = &\min\{ u \alt t\leq s\to u\}
\\
\worra t s = \min\{u \alt t\circ(\dom t\setminus u)\leq\neg s\}\label{worra}
\worra t s &= &\min\{u \alt t\circ(\dom t\setminus u)\leq\neg s\}\label{worra}
\end{eqnarray}
The first two operators belongs to the theory of semantic subtyping while the last one is new and we described it in Section~\ref{sec:ideas}
...
...
@@ -597,7 +602,7 @@ We need similar operators for projections since the type $t$ of $e$ in $\pi_i e$
\bpl t & = &\min\{ u \alt t\leq\pair u\Any\}\\
\bpr t & = &\min\{ u \alt t\leq\pair\Any u\}
\end{eqnarray}
All the operators above but $\worra{}{}$ are already present in the theory of semantic subtyping. The reader can find how to compute them and how to extend them to type schemes in~\cite[Section 6.11]{Frisch2008}. Below we just show the formula that computes $\worra t s$ for a $t$ subtype of $\Empty\to\Any$. For that, we use a result of semantic subtyping that states that every type $t$ is equivalent to a type in disjunctive normal form and that if furthermore $t\leq\Empty\to\Any$, then $t \simeq\bigvee_{i\in I}\left(\bigwedge_{p\in P_i}(s_p\to t_p)\bigwedge_{n\in N_i}\neg(s_n'\to t_n')\right)$ with $\bigwedge_{p\in P_i}(s_p\to t_p)\bigwedge_{n\in N_i}\neg(s_n'\to t_n')\not\simeq\Empty$ for all $i$ in $I$. For such a $t$ and any type $s$ then we have:
All the operators above but $\worra{}{}$ are already present in the theory of semantic subtyping. The reader can find how to compute them and how to extend their definition to type schemes in~\cite[Section 6.11]{Frisch2008}. Below we just show the formula that computes $\worra t s$ for a $t$ subtype of $\Empty\to\Any$. For that, we use a result of semantic subtyping that states that every type $t$ is equivalent to a type in disjunctive normal form and that if furthermore $t\leq\Empty\to\Any$, then $t \simeq\bigvee_{i\in I}\left(\bigwedge_{p\in P_i}(s_p\to t_p)\bigwedge_{n\in N_i}\neg(s_n'\to t_n')\right)$ with $\bigwedge_{p\in P_i}(s_p\to t_p)\bigwedge_{n\in N_i}\neg(s_n'\to t_n')\not\simeq\Empty$ for all $i$ in $I$. For such a $t$ and any type $s$ then we have:
%
\begin{equation}
\worra t s = \dom t \wedge\bigvee_{i\in I}\left(\bigwedge_{\{P\subset P_i\alt s\leq\bigvee_{p \in P}\neg t_p\}}\left(\bigvee_{p \in P}\neg s_p\right) \right)