In this section we present the formalization of the ideas we hinted in the introduction. We start by the definitions of types. Next we define the language and its reduction semantics. The static semantics is the core of our presentation: we first present a declarative types system which deduces for every well-typed expressions several types and then the algorithms that allow us to decide well typedness.

\subsection{Types}

\begin{definition}[Type syntax]\label{def:types} The set of types \types{} are the terms $t$ coinductively produced by the following grammar

\[

\begin{array}{lrcl}

\textbf{Types}& t & ::=& b\alt t\to t\alt t\times t\alt t\vee t \alt\neg t \alt\Empty

\end{array}

\]

and that satisfy the following conditions

\begin{itemize}

\item (regularity) the term has a finite number of different sub-terms;

\item (contractivity) every infinite branch of a type contains an infinite number of occurrences of the

...) which are values of basic types (we use $\basic{c}$ to denote the

basic type of the constant $c$); $x$ ranges over variables; $(e,e)$

denote pairs and $\pi_i e$ their projections; $\tcase{e}{t}{e_1}{e_2}$

denotes the type-case expression that evaluates either $e_1$ or $e_2$

according to whether the value returned by $e$ (if any) is of type $t$

or not; $\lambda^{\wedge_{i\in I}s_i\to t_i} x.e$ is a value of type

$\wedge_{i\in I}s_i\to t_i$ and denotes the function of parameter $x$

and body $e$. An expression has an intersection type if and only if it

has all the types that compose the intersection. Therefore,

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 said

described the types of constants and abstractions and, inductively,

the type of a pair of values is the product of the types of the

values.

\subsection{Syntax}

\subsection{Dynamic semantics}

uses type schemes?

The dynamic semantics is defined as a classic left-to-right reduction with pairs with a specific rule for type-cases. We have the following notions of reduction:

\[

\begin{array}{rcll}

(\lambda^{\wedge_{i\in I}s_i\to t_i} x.e)v &\reduces& e\subst x v\\

\pi_i(v_1,v_2)&\reduces& v_i & i=1,2\\

\tcase{v}{t}{e_1}{e_2}&\reduces& e_1&v\in t\\

\tcase{v}{t}{e_1}{e_2}&\reduces& e_2&v\not\in t\\

\end{array}

\]

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