Add paragraph about the typing of the typecase

This commit is contained in:
regnat 2017-04-27 12:24:23 +02:00
parent e8070bbb13
commit 864957720a

View File

@ -20,6 +20,25 @@ concrete typing environments. So for example, $\ofTypeP{\{ x, y \}}{\{ x = \τ;
y = \σ \}}$ is equal to the typing constraints $x : $ and $y : \σ$, which may
be used to type the body of the corresponding function.
\subsubsection{Typecase}
The typecase $(x := e \in t) ? e_1 : e_2$ can be typed in a simple way, by
saying that if $e$ has a type $τ$, $e_1$ has type $_1$ and $e_2$ has type
$_2$ (under the current typing environment $$), then $(x := e \in t) ? e_1
: e_2$ has type $_1 \vee _2$.
However, doing so means that we do not use the extra type information given by
"$e \in t$", which loosens a lot the interest of this construct. For example,
an expression such as $(x := e \in \bm{{Int}}) ? x + 1 : x$, with $\vdash e :
\any$ wouldn't typecheck, as $x+1$ isn't well typed without any further
constraint on the type of $x$.
A more interesting typing rule would state that if $; x: \wedge t \vdash e_1:
_1$ and $; x: \wedge \lnot t \vdash e_2: _2$ (where $$ is a type of
$e$ under the hypothesis $$), then the whole expression has type $_1 \vee
_2$.
With this rule, the expression $(x := e \in \bm{{Int}}) ? x + 1 : x$ is
well-typed (provided that $e$ is).
The typing rules are given by the
figures~\pref{typing::lambda-calculus},~\pref{typing::records}
and~\pref{typing::operators}.