mirror of
https://github.com/dhil/phd-dissertation
synced 2026-03-13 11:08:25 +00:00
Tracking of divergence (discussion).
This commit is contained in:
11
thesis.bib
11
thesis.bib
@@ -769,3 +769,14 @@
|
|||||||
pages = {346--366},
|
pages = {346--366},
|
||||||
volume = {33}
|
volume = {33}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Termination analysis.
|
||||||
|
@article{Walther94,
|
||||||
|
author = {Christoph Walther},
|
||||||
|
title = {On Proving the Termination of Algorithms by Machine},
|
||||||
|
journal = {Artif. Intell.},
|
||||||
|
volume = {71},
|
||||||
|
number = {1},
|
||||||
|
pages = {101--157},
|
||||||
|
year = {1994}
|
||||||
|
}
|
||||||
67
thesis.tex
67
thesis.tex
@@ -63,6 +63,10 @@
|
|||||||
\newtheorem{proposition}[theorem]{Proposition}
|
\newtheorem{proposition}[theorem]{Proposition}
|
||||||
\newtheorem{corollary}[theorem]{Corollary}
|
\newtheorem{corollary}[theorem]{Corollary}
|
||||||
\newtheorem{definition}[theorem]{Definition}
|
\newtheorem{definition}[theorem]{Definition}
|
||||||
|
% Example environment.
|
||||||
|
\makeatletter
|
||||||
|
\def\@endtheorem{\hfill$\blacksquare$\endtrivlist\@endpefalse} % inserts a black square at the end.
|
||||||
|
\makeatother
|
||||||
\theoremstyle{definition}
|
\theoremstyle{definition}
|
||||||
\newtheorem{example}{Example}[chapter]
|
\newtheorem{example}{Example}[chapter]
|
||||||
|
|
||||||
@@ -1192,7 +1196,11 @@ customary factorial function.
|
|||||||
\ba[t]{@{}l}
|
\ba[t]{@{}l}
|
||||||
\Let\;is\_zero \revto n = 0\;\In\\
|
\Let\;is\_zero \revto n = 0\;\In\\
|
||||||
\If\;is\_zero\;\Then\; \Return\;1\\
|
\If\;is\_zero\;\Then\; \Return\;1\\
|
||||||
\Else\;\Let\; n' \revto n - 1 \;\In\;f~n'
|
\Else\;\ba[t]{@{~}l}
|
||||||
|
\Let\; n' \revto n - 1 \;\In\\
|
||||||
|
\Let\; m \revto f~n' \;\In\\
|
||||||
|
n * m
|
||||||
|
\ea
|
||||||
\ea
|
\ea
|
||||||
\el
|
\el
|
||||||
\]
|
\]
|
||||||
@@ -1214,7 +1222,7 @@ The key to track divergence is to modify the \tylab{Rec} to inject
|
|||||||
some primitive operation into the effect row.
|
some primitive operation into the effect row.
|
||||||
%
|
%
|
||||||
\begin{mathpar}
|
\begin{mathpar}
|
||||||
\inferrule*[Lab=\tylab{Rec}]
|
\inferrule*[Lab=$\tylab{Rec}^\ast$]
|
||||||
{\typ{\Delta;\Gamma,f : A \to B\eff\{\dec{Div}:\Zero\}, x : A}{M : B\eff\{\dec{Div}:\Zero\}}}
|
{\typ{\Delta;\Gamma,f : A \to B\eff\{\dec{Div}:\Zero\}, x : A}{M : B\eff\{\dec{Div}:\Zero\}}}
|
||||||
{\typ{\Delta;\Gamma}{(\Rec \; f^{A \to B\eff\{\dec{Div}:\Zero\}} \, x .M) : A \to B\eff\{\dec{Div}:\Zero\}}}
|
{\typ{\Delta;\Gamma}{(\Rec \; f^{A \to B\eff\{\dec{Div}:\Zero\}} \, x .M) : A \to B\eff\{\dec{Div}:\Zero\}}}
|
||||||
\end{mathpar}
|
\end{mathpar}
|
||||||
@@ -1231,22 +1239,21 @@ every application-site of $\dec{fac}$ must now permit the $\dec{Div}$
|
|||||||
operation in order to type check.
|
operation in order to type check.
|
||||||
%
|
%
|
||||||
\begin{example}
|
\begin{example}
|
||||||
Consider the following ill-typed suspended computation which is
|
We will use the following suspended computation to demonstrate
|
||||||
intended to compute the $3!$ when forced.
|
effect tracking in action.
|
||||||
%
|
%
|
||||||
\[
|
\[
|
||||||
\bl
|
\bl
|
||||||
\dec{fac_3} : \Unit \to \Int \eff \emptyset\\
|
\lambda\Unit. \dec{fac}~3
|
||||||
\dec{fac_3} \defas \lambda\Unit. \dec{fac}~3
|
|
||||||
\el
|
\el
|
||||||
\]
|
\]
|
||||||
%
|
%
|
||||||
We will now show that this suspended computation fails to type check
|
The computation calculates $3!$ when forced.
|
||||||
with the above type signature. Let
|
%
|
||||||
$\Gamma = \{\dec{fac} : \Int \to \Int \eff
|
We will now give a typing derivation for this computation to
|
||||||
\{\dec{Div}:\Zero\}\}$. The following typing derivation shows that
|
illustrate how the application of $\dec{fac}$ causes its effect row
|
||||||
the application of $\dec{fac}$ causes its effect row to be
|
to be propagated outwards. Let
|
||||||
propagated outwards.
|
$\Gamma = \{\dec{fac} : \Int \to \Int \eff \{\dec{Div}:\Zero\}\}$.
|
||||||
%
|
%
|
||||||
\begin{mathpar}
|
\begin{mathpar}
|
||||||
\inferrule*[Right={\tylab{Lam}}]
|
\inferrule*[Right={\tylab{Lam}}]
|
||||||
@@ -1259,12 +1266,38 @@ operation in order to type check.
|
|||||||
{\typ{\emptyset;\Gamma}{\lambda\Unit.\dec{fac}~3} : \Unit \to \Int \eff \{\dec{Div}:\Zero\}}
|
{\typ{\emptyset;\Gamma}{\lambda\Unit.\dec{fac}~3} : \Unit \to \Int \eff \{\dec{Div}:\Zero\}}
|
||||||
\end{mathpar}
|
\end{mathpar}
|
||||||
%
|
%
|
||||||
It follows from the typing derivation that the effect row on
|
The information that the computation applies a possibly divergent
|
||||||
$\dec{fac_3}$ cannot be empty. In other words, the information that
|
function internally gets reflected externally in its effect
|
||||||
$\dec{fac_3}$ applies a possibly divergent function internally must
|
signature.
|
||||||
be reflected externally in its effect signature.
|
|
||||||
\end{example}
|
\end{example}
|
||||||
|
%
|
||||||
|
A possible inconvenience of the current formulation of
|
||||||
|
$\tylab{Rec}^\ast$ is that it recursion cannot be mixed with other
|
||||||
|
computational effects. The reason being that the effect row on
|
||||||
|
$A \to B\eff \{\dec{Div}:\Zero\}$ is closed. Thus in practical
|
||||||
|
programming language implementation it would be more convenient to
|
||||||
|
leave the tail of the effect row open as to allow recursion to be used
|
||||||
|
in larger effect contexts. The rule formulation is also rather coarse
|
||||||
|
as it renders every $\Rec$-definition as possibly divergent -- even
|
||||||
|
definitions that are obviously non-divergent such as the
|
||||||
|
$\Rec$-variation of the identity function: $\Rec\;f\,x.x$. A practical
|
||||||
|
implementation could utilise a static termination
|
||||||
|
checker~\cite{Walther94} to obtain more fine-grained tracking of
|
||||||
|
divergence.
|
||||||
|
% By fairly lightweight means we can obtain a finer analysis of
|
||||||
|
% $\Rec$-definitions by simply having an additional typing rule for
|
||||||
|
% the application of $\Rec$.
|
||||||
|
% %
|
||||||
|
% \begin{mathpar}
|
||||||
|
% \inferrule*[lab=$\tylab{AppRec}^\ast$]
|
||||||
|
% { E' = \{\dec{Div}:\Zero\} \uplus E\\
|
||||||
|
% \typ{\Delta}{E'}\\\\
|
||||||
|
% \typ{\Delta;\Gamma}{\Rec\;f^{A \to B \eff E}\,x.M : A \to B \eff E}\\
|
||||||
|
% \typ{\Delta;\Gamma}{W : A}
|
||||||
|
% }
|
||||||
|
% {\typ{\Delta;\Gamma}{(\Rec\;f^{A \to B \eff E}\,x.M)\,W : B \eff E'}}
|
||||||
|
% \end{mathpar}
|
||||||
|
% %
|
||||||
|
|
||||||
\section{Row polymorphism}
|
\section{Row polymorphism}
|
||||||
\label{sec:row-polymorphism}
|
\label{sec:row-polymorphism}
|
||||||
|
|||||||
Reference in New Issue
Block a user