Fix TamedFJ introduction
This commit is contained in:
parent
49368e0d0e
commit
3dbdce8e29
52
tRules.tex
52
tRules.tex
@ -5,33 +5,56 @@
|
|||||||
%Input language only described here. It is standard Featherweight Java
|
%Input language only described here. It is standard Featherweight Java
|
||||||
% we use the transformation to proof soundness. this could also be moved to the end.
|
% we use the transformation to proof soundness. this could also be moved to the end.
|
||||||
% the constraint generation step assumes every method argument to be encapsulated in a let statement. This is the way Java is doing capture conversion
|
% the constraint generation step assumes every method argument to be encapsulated in a let statement. This is the way Java is doing capture conversion
|
||||||
|
We define our own calculus \TamedFJ{}, which is used as input aswell as output to our global type inference algorithm.
|
||||||
The input to our algorithm is a typeless version of Featherweight Java.
|
%We assume that the input to our algorithm is a program, which carries none of the optional type annotations.
|
||||||
|
%After calculating a type solution we can insert all missing types and generate a correct program.
|
||||||
|
%The input to our algorithm is a typeless version of Featherweight Java.
|
||||||
The syntax is shown in figure \ref{fig:syntax} with optional type annotations highlighted in yellow.
|
The syntax is shown in figure \ref{fig:syntax} with optional type annotations highlighted in yellow.
|
||||||
The respective type rules are defined by figure \ref{fig:expressionTyping} and \ref{fig:typing}.
|
The respective type rules are defined by figure \ref{fig:expressionTyping} and \ref{fig:typing}.
|
||||||
\TamedFJ{} is a subset of the calculus defined by \textit{Bierhoff} \cite{WildcardsNeedWitnessProtection}.
|
\TamedFJ{} is practically a subset of the Featherweight Java calculus defined by \textit{Bierhoff} \cite{WildcardsNeedWitnessProtection}
|
||||||
|
with the exception that method argument and return type annotations are optional.
|
||||||
The point is that a correct and fully typed \TamedFJ{} program is also a correct Featherweight Java program,
|
The point is that a correct and fully typed \TamedFJ{} program is also a correct Featherweight Java program,
|
||||||
which is vital for our soundness proof (see chapter \ref{sec:soundness}).
|
which is vital for our soundness proof (see chapter \ref{sec:soundness}).
|
||||||
%The language is designed to showcase type inference involving existential types.
|
%The language is designed to showcase type inference involving existential types.
|
||||||
This calculus is used as input aswell as output to our global type inference algorithm.
|
|
||||||
We assume that the input to our algorithm is a program, which carries none of the optional type annotations.
|
|
||||||
After calculating a type solution we can insert all missing types and generate a correct program.
|
|
||||||
|
|
||||||
A method assumption consists out of a method name, a list of type parameters, a list of argument types, and a return type.
|
A method assumption consists out of a method name, a list of type parameters, a list of argument types, and a return type.
|
||||||
The first argument type is the type of the surrounding class or the \texttt{this} parameter one could say.
|
The first type in the list of argument types is the type of the surrounding class also known as the \texttt{this} parameter.
|
||||||
For example the \texttt{add} method in listing \ref{lst:tamedfjSample} is represented by the assumption
|
See figure \ref{fig:methodTypeExample} for an example:
|
||||||
$\texttt{add} : \generics{\ol{X \triangleleft Object}}\ \type{X} \to \exptype{List}{\type{X}}$.
|
Here the \texttt{add} method internally is treated as a method with two arguments,
|
||||||
\begin{lstlisting}[style=java,caption=\TamedFJ{} sample, label=lst:tamedfjSample]
|
because we add \texttt{this} to its argument list.
|
||||||
|
Note that the type parameter $\type{A}$ of the surrounding class is part of the methods parameter list.
|
||||||
|
%For example the \texttt{add} method in listing \ref{lst:tamedfjSample} is represented by the assumption
|
||||||
|
%$\texttt{add} : \generics{\ol{X \triangleleft Object}}\ \type{X} \to \exptype{List}{\type{X}}$.
|
||||||
|
\begin{figure}
|
||||||
|
\center
|
||||||
|
\begin{minipage}{0.49\textwidth}
|
||||||
|
%[style=java,caption=\TamedFJ{} sample, label=lst:tamedfjSample]
|
||||||
|
\begin{lstlisting}
|
||||||
class List<A extends Object> {
|
class List<A extends Object> {
|
||||||
List<A> add(A v){..,}
|
List<A> add(A v){..,}
|
||||||
}
|
}
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
TODO
|
\end{minipage}
|
||||||
\\[1em]
|
\begin{minipage}{0.49\textwidth}
|
||||||
\noindent
|
\begin{align*}
|
||||||
|
&\mathrm{\Pi} = \set{\\
|
||||||
|
&\texttt{add} : \generics{\ol{A \triangleleft Object}}\ \exptype{List}{\type{A}},\type{A} \to \exptype{List}{\type{X}} \\
|
||||||
|
&}
|
||||||
|
\end{align*}
|
||||||
|
\end{minipage}
|
||||||
|
% \begin{minipage}{0.49\textwidth}
|
||||||
|
% \begin{lstlisting}[style=java,caption=\TamedFJ{} sample, label=lst:tamedfjSample]
|
||||||
|
% class List<A extends Object> {}
|
||||||
|
% <A extends Object> List<A>
|
||||||
|
% add(List<A> this, A v){..,}
|
||||||
|
% \end{lstlisting}
|
||||||
|
% \end{minipage}
|
||||||
|
\caption{\TamedFJ{} class and its corresponding method type environment}\label{fig:methodTypeExample}
|
||||||
|
\end{figure}
|
||||||
|
|
||||||
\textit{Additional Notes:}%
|
\textit{Additional Notes:}%
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item Method parameters and return types are optional.
|
%\item Method parameters and return types are optional.
|
||||||
\item We still require type annotations for fields and generic class parameters.
|
\item We still require type annotations for fields and generic class parameters.
|
||||||
This is a design choice by us,
|
This is a design choice by us,
|
||||||
as we consider them as data declarations which are given by the programmer.
|
as we consider them as data declarations which are given by the programmer.
|
||||||
@ -85,6 +108,7 @@ $
|
|||||||
& & \ \ | & \texttt{let}\ \expr{x} \highlight{: \wcNtype{\Delta}{N}} = \expr{e} \ \texttt{in} \ \expr{e}\\
|
& & \ \ | & \texttt{let}\ \expr{x} \highlight{: \wcNtype{\Delta}{N}} = \expr{e} \ \texttt{in} \ \expr{e}\\
|
||||||
& & \ \ | & \expr{e} \elvis{} \expr{e}\\
|
& & \ \ | & \expr{e} \elvis{} \expr{e}\\
|
||||||
\text{Variable contexts} & \Gamma & ::= & \overline{\expr{x}:\type{T}}\\
|
\text{Variable contexts} & \Gamma & ::= & \overline{\expr{x}:\type{T}}\\
|
||||||
|
\text{Method type environment} & \mathrm{\Pi} & ::= & \overline{ \texttt{m} : \generics{\ol{X \triangleleft N}}\ \ol{T} \to \type{T}}
|
||||||
%\hline
|
%\hline
|
||||||
\end{array}
|
\end{array}
|
||||||
$
|
$
|
||||||
|
Loading…
Reference in New Issue
Block a user