Browse Source

cupto WIP

master
Daniel Hillerström 5 years ago
parent
commit
5c27694161
  1. 1
      macros.tex
  2. 23
      thesis.bib
  3. 62
      thesis.tex

1
macros.tex

@ -453,3 +453,4 @@
\newcommand{\Cont}{\dec{Cont}}
\newcommand{\Algol}{Algol~60}
\newcommand{\qq}[1]{\ensuremath{\ulcorner #1 \urcorner}}
\newcommand{\prompttype}{\dec{Prompt}}

23
thesis.bib

@ -2185,3 +2185,26 @@
publisher = {{ACM}},
year = {2017}
}
# Hindley-Milner type inference
@article{Hindley69,
optISSN = {00029947},
optURL = {http://www.jstor.org/stable/1995158},
author = {Roger Hindley},
journal = {Transactions of the AMS},
pages = {29--60},
publisher = {{AMS}},
title = {The Principal Type-Scheme of an Object in Combinatory Logic},
volume = {146},
year = {1969}
}
@article{Milner78,
author = {Robin Milner},
title = {A Theory of Type Polymorphism in Programming},
journal = {J. Comput. Syst. Sci.},
volume = {17},
number = {3},
pages = {348--375},
year = {1978}
}

62
thesis.tex

@ -1634,9 +1634,9 @@ translation in Standard ML New Jersey~\cite{AppelM91}, using
\citeauthor{Filinski94}'s encoding of shift/reset in terms of callcc
and state~\cite{Filinski94}.
%
%
\dhil{Maybe mention the implication is that control/prompt has CPS semantics.}
\dhil{Mention shift0/reset0, dollar0\dots}
% \begin{reductions}
% % \slab{Value} & \reset{V} &\reducesto& V\\
% \slab{Capture} & \reset{\EC[\shift\,k.M]} &\reducesto& M[\cont_{\reset{\EC}}/k]\\
@ -1644,15 +1644,67 @@ and state~\cite{Filinski94}.
% \end{reductions}
%
\paragraph{Cupto}
\paragraph{Cupto} The control operator cupto is a variation of
control0/prompt0 designed to fit into the typed ML-family of
languages. It was introduced by \citet{GunterRR95} in 1995. The name
cupto is an abbreviation for ``control up to''~\cite{GunterRR95}.
%
The control operator comes with a set of companion constructs, and
thus, augments the syntactic categories of types, values, and
computations.
%
\begin{syntax}
& A,B &::=& \cdots \mid \prompttype~A \smallskip\\
& V,W &::=& \cdots \mid p \mid \newPrompt\\
& M,N &::=& \cdots \mid \Set\;V\;\In\;N \mid \Cupto~V~k.M
\end{syntax}
%
The type $\prompttype~A$ is the type of prompts. It is parameterised
by an answer type $A$ for the prompt context. Prompts are first-class
values, which we denote by $p$. The construct $\newPrompt$ is a
special function symbol, which returns a fresh prompt. The computation
form $\Set\;V\;\In\;N$ activates the prompt $V$ to delimit the dynamic
extent of continuations captured inside $N$. The $\Cupto~V~k.M$
computation binds $k$ to the continuation up to (the first instance
of) the active prompt $V$ in the computation $M$.
\citet{GunterRR95} gave a Hindley-Milner type
system~\cite{Hindley69,Milner78} for $\Cupto$, since they were working
in the context of ML languages. I do not reproduce the full system
here, only the essential rules for the $\Cupto$ constructs.
%
\begin{mathpar}
\inferrule*
{~}
{\typ{\Gamma,p:\prompttype~A}{p : \prompttype~A}}
\inferrule*
{~}
{\typ{\Gamma}{\newPrompt} : \UnitType \to \prompttype~A}
\inferrule*
{\typ{\Gamma}{V : \prompttype~A} \\ \typ{\Gamma}{N : A}}
{\typ{\Gamma}{\Set\;V\;\In\;N : A}}
\inferrule*
{\typ{\Gamma}{V : \prompttype~B} \\ \typ{\Gamma,k : A \to B}{M : B}}
{\typ{\Gamma}{\Cupto\;V\;k.M : A}}
\end{mathpar}
%
%val cupto : 'b prompt -> (('a -> 'b) -> 'b) -> 'a
%
The typing rule for $\Set$ uses the type embedded in the prompt to fix
the type of the whole computation $N$. Similarly, the typing rule for
$\Cupto$ uses the prompt type of its value argument to fix the answer
type for the continuation $k$.
%
\begin{reductions}
\slab{Value} &
\Set\; p \;\In\; V, \rho &\reducesto& V, \rho\\
\slab{New\textrm{-}prompt} &
\newPrompt, \rho &\reducesto& p, \rho \uplus \{p\}\\
\slab{NewPrompt} &
\newPrompt~\Unit, \rho &\reducesto& p, \rho \uplus \{p\}\\
\slab{Capture} &
\Set\; p \;\In\; \EC[\Cupto~p~k.M], \rho &\reducesto& M[\cont_{\EC}/k], \rho\\
\Set\; p \;\In\; \EC[\Cupto~p~k.M], \rho &\reducesto& M[\qq{\cont_{\EC}}/k], \rho\\
\slab{Resume} & \Continue~\cont_{\EC}~V, \rho &\reducesto& \EC[V], \rho
\end{reductions}

Loading…
Cancel
Save