2024-03-05 23:33:54 +00:00
\section { Syntax and Typing} \label { sec:tifj}
2024-02-07 16:29:41 +00:00
The input syntax for our algorithm is shown in figure \ref { fig:syntax}
and the respective type rules in figure \ref { fig:expressionTyping} and \ref { fig:typing} .
2024-02-10 07:19:24 +00:00
Our algorithm is an extension of the \emph { Global Type Inference for Featherweight Generic Java} \cite { TIforFGJ} algorithm.
2024-02-09 20:49:12 +00:00
The input language is designed to showcase type inference involving existential types.
2024-02-10 07:19:24 +00:00
Method call rule T-Call is the most interesting part, because it emulates the behaviour of a Java method call,
2024-02-09 20:49:12 +00:00
where existential types are implicitly \textit { opened} and \textit { closed} .
2024-02-10 07:19:24 +00:00
2024-03-05 23:33:54 +00:00
Example: %TODO
\begin { verbatim}
class List<A> {
A head;
List<A> tail;
add(v) = new List(v, this);
}
\end { verbatim}
2024-03-06 15:08:12 +00:00
%The rules depicted here are type inference rules. It is not possible to derive a distinct typing from a given input program.
2024-02-10 07:19:24 +00:00
%The T-Elvis rule mimics the type judgement of a branch expression like \texttt{if-else}.
%and is solely used for examples.
2024-02-11 22:29:34 +00:00
The calculus does not include method overriding for simplicity reasons.
Type inference for that is described in \cite { TIforFGJ} and can be added to this algorithm accordingly.
2024-02-10 07:19:24 +00:00
Our algorithm is designed for extensibility with the final goal of full support for Java.
\unify { } is the core of the algorithm and can be used for any calculus sharing the same subtype relations as depicted in \ref { fig:subtyping} .
Additional language constructs can be added by implementing the respective constraint generation functions in the same fashion as described in chapter \ref { chapter:constraintGeneration} .
%Additional features like overriding methods and method overloading can be added by copying the respective parts from there.
2024-02-09 20:49:12 +00:00
%Additional features can be easily added by generating the respective constraints (Plümicke hier zitieren)
2024-02-10 07:19:24 +00:00
% The type system in \cite{WildcardsNeedWitnessProtection} allows a method to \textit{override} an existing method declaration in one of its super classes,
% but only by a method with the exact same type.
% The type system presented here does not allow the \textit{overriding} of methods.
% Our type inference algorithm consumes the input classes in succession and could only do a type check instead of type inference
% on overriding methods, because their type is already determined.
% Allowing overriding therefore has no implication on our type inference algorithm.
2024-02-07 16:29:41 +00:00
2024-03-28 02:40:39 +00:00
The syntax forces every expression to undergo a capture conversion before it can be used as a method argument.
Even variables have to be catched by a let statement first.
This behaviour emulates Java's implicit capture conversion.
2024-02-07 09:28:28 +00:00
\begin { figure}
2023-12-31 02:32:26 +00:00
$
\begin { array} { lrcl}
\hline
2024-02-07 09:28:28 +00:00
\text { Parameterized classes} & \mv N & ::= & \exptype { C} { \ol { T} } \\
2023-12-31 02:32:26 +00:00
\text { Types} & \type { S} , \type { T} , \type { U} & ::= & \type { X} \mid \wcNtype { \Delta } { N} \\
\text { Lower bounds} & \type { K} , \type { L} & ::= & \type { T} \mid \bot \\
\text { Type variable contexts} & \Delta & ::= & \overline { \wildcard { X} { T} { L} } \\
\text { Class declarations} & D & ::= & \texttt { class} \ \exptype { C} { \ol { X \triangleleft T} } \triangleleft \type { N} \set { \overline { \type { T} \ f} ; \ol { M} } \\
2024-05-02 14:14:00 +00:00
\text { Method declarations} & \texttt { M} & ::= & \texttt { m} (\overline { \expr { x} } ) \set { \texttt { return} \ t;} \\
2024-03-28 02:40:39 +00:00
\text { Terms} & t & ::= & \expr { x} \\
& & \ \ | & \texttt { let} \ \overline { \expr { x} _ c} = \overline { t} \ \texttt { in} \ \texttt { new} \ \type { C} (\overline { \expr { x} _ c} ) \\
& & \ \ | & \texttt { let} \ \expr { x} _ c = t \ \texttt { in} \ \expr { x} _ c.f \\
& & \ \ | & \texttt { let} \ \expr { x} _ c = t \ \texttt { in} \ \texttt { let} \ \overline { \expr { x} _ c} = \overline { t} \ \texttt { in} \ \expr { x} _ c.\texttt { m} (\overline { \expr { x} _ c} ) \\
& & \ \ | & t \elvis { } t \\
\text { Variable contexts} & \Gamma & ::= & \overline { \expr { x} :\type { T} } \\
2023-12-31 02:32:26 +00:00
\hline
\end { array}
$
2024-03-29 23:07:26 +00:00
\caption { \TamedFJ { } Syntax} \label { fig:syntax}
2024-02-07 09:28:28 +00:00
\end { figure}
2023-12-31 02:32:26 +00:00
2024-03-28 02:40:39 +00:00
% \begin{figure}
% $
% \begin{array}{lrcl}
% \hline
% \text{Parameterized classes} & \mv N & ::= & \exptype{C}{\ol{T}} \\
% \text{Types} & \type{S}, \type{T}, \type{U} & ::= & \type{X} \mid \wcNtype{\Delta}{N} \\
% \text{Lower bounds} & \type{K}, \type{L} & ::= & \type{T} \mid \bot \\
% \text{Type variable contexts} & \Delta & ::= & \overline{\wildcard{X}{T}{L}} \\
% \text{Class declarations} & D & ::= & \texttt{class}\ \exptype{C}{\ol{X \triangleleft T}} \triangleleft \type{N} \set{\overline{\type{T}\ f}; \ol{M}} \\
% \text{Method declarations} & \texttt{M} & ::= & \texttt{m}(\overline{\expr{x}}) = t \\
% \text{Values} & v & ::= & \expr{x} \\
% \text{Terms} & t & ::= & v \\
% & & \ \ | & \texttt{let} \ \expr{x} = \texttt{new} \ \type{C}(\overline{v}) \ \texttt{in} \ t \\
% & & \ \ | & \texttt{let} \ \expr{x} = v.f \ \texttt{in} \ t \\
% & & \ \ | & \texttt{let} \ \expr{x} = v.\texttt{m}(\overline{v}) \ \texttt{in} \ t \\
% & & \ \ | & \texttt{let} \ \expr{x} = v \elvis{} v \ \texttt{in} \ t \\
% \text{Variable contexts} & \Gamma & ::= & \overline{\expr{x}:\type{T}}\\
% \hline
% \end{array}
% $
% \caption{Input Syntax}\label{fig:syntax}
% \end{figure}
% \begin{figure}
% $
% \begin{array}{lrcl}
% \hline
% \text{Parameterized classes} & \mv N & ::= & \exptype{C}{\ol{T}} \\
% \text{Types} & \type{S}, \type{T}, \type{U} & ::= & \type{X} \mid \wcNtype{\Delta}{N} \\
% \text{Lower bounds} & \type{K}, \type{L} & ::= & \type{T} \mid \bot \\
% \text{Type variable contexts} & \Delta & ::= & \overline{\wildcard{X}{T}{L}} \\
% \text{Class declarations} & D & ::= & \texttt{class}\ \exptype{C}{\ol{X \triangleleft T}} \triangleleft \type{N} \set{\overline{\type{T}\ f}; \ol{M}} \\
% \text{Method declarations} & \texttt{M} & ::= & \texttt{m}(\overline{\expr{x}}) = t \\
% \text{Terms} & t & ::= & \expr{x} \\
% & & \ \ | & \texttt{let} \ \expr{x} = t \ \texttt{in} \ t \\
% & & \ \ | & \expr{x}.f \\
% & & \ \ | & \expr{x}.\texttt{m}(\overline{\expr{x}}) \\
% & & \ \ | & t \elvis{} t \\
% \text{Variable contexts} & \Gamma & ::= & \overline{\expr{x}:\type{T}}\\
% \hline
% \end{array}
% $
% \caption{Input Syntax}\label{fig:syntax}
% \end{figure}
% \begin{figure}
% $
% \begin{array}{lrcl}
% \hline
% \text{Parameterized classes} & \mv N & ::= & \exptype{C}{\ol{T}} \\
% \text{Types} & \type{S}, \type{T}, \type{U} & ::= & \type{X} \mid \wcNtype{\Delta}{N} \\
% \text{Lower bounds} & \type{K}, \type{L} & ::= & \type{T} \mid \bot \\
% \text{Type variable contexts} & \Delta & ::= & \overline{\wildcard{X}{T}{L}} \\
% \text{Class declarations} & D & ::= & \texttt{class}\ \exptype{C}{\ol{X \triangleleft T}} \triangleleft \type{N} \set{\overline{\type{T}\ f}; \ol{M}} \\
% \text{Method declarations} & \texttt{M} & ::= & \texttt{m}(\overline{x}) = t \\
% \text{Terms} & t & ::= & x \\
% & & \ \ | & \texttt{new} \ \type{C}(\overline{t})\\
% & & \ \ | & t.f\\
% & & \ \ | & t.\texttt{m}(\overline{t})\\
% & & \ \ | & t \elvis{} t\\
% \text{Variable contexts} & \Gamma & ::= & \overline{x:\type{T}}\\
% \hline
% \end{array}
% $
% \caption{Input Syntax}\label{fig:syntax}
% \end{figure}
2024-04-08 19:45:29 +00:00
\subsection { ANF transformation} \label { sec:anfTransformation}
2024-03-28 02:40:39 +00:00
\newcommand { \anf } [1]{ \ensuremath { \tau } (#1)}
%https://en.wikipedia.org/wiki/A-normal_form)
Featherweight Java's syntax involves no \texttt { let} statement
and terms can be nested freely.
This is similar to Java's syntax.
To convert it to \TamedFJ { } additional let statements have to be added.
2024-03-29 23:07:26 +00:00
This is done by a \textit { A-Normal Form} \cite { aNormalForm} transformation shown in figure \ref { fig:anfTransformation} .
The input of this transformation is a Featherweight Java program in the syntax given \ref { fig:inputSyntax}
and the output is a \TamedFJ { } program.
2024-03-28 02:40:39 +00:00
\textit { Example:} \\
\noindent
\begin { minipage} { 0.45\textwidth }
\begin { lstlisting} [style=fgj,caption=Featherweight Java]
m(l, v){
2024-03-29 23:07:26 +00:00
return l.add(v);
2024-03-28 02:40:39 +00:00
}
\end { lstlisting}
\end { minipage} %
\hfill
\begin { minipage} { 0.5\textwidth }
\begin { lstlisting} [style=tfgj,caption=\TamedFJ { } representation]
m(l, v) =
2024-03-29 23:07:26 +00:00
let x1 = l in
let x2 = v in x1.add(x2)
2024-03-28 02:40:39 +00:00
\end { lstlisting}
\end { minipage}
2024-03-29 23:07:26 +00:00
% $
% \begin{array}{|lrcl|l}
% \hline
% & & & \textbf{Featherweight Java Terms}\\
% \text{Terms} & t & ::=
% & \expr{x}
% \\
% & & \ \ |
% & \texttt{new} \ \type{C}(\overline{t})
% \\
% & & \ \ |
% & t.f
% \\
% & & \ \ |
% & t.\texttt{m}(\overline{t})
% \\
% & & \ \ |
% & t \elvis{} t\\
% %
% \hline
% \end{array}
% $
2024-03-28 02:40:39 +00:00
2024-03-29 23:07:26 +00:00
\begin { figure}
\begin { center}
2024-03-28 02:40:39 +00:00
$ \begin { array } { lrcl }
2024-03-29 23:07:26 +00:00
%\text{ANF}
& \anf { \expr { x} } & = & \expr { x} \\
2024-03-28 02:40:39 +00:00
& \anf { \texttt { new} \ \type { C} (\overline { t} )} & = & \texttt { let} \ \overline { \expr { x} } = \anf { \overline { t} } \ \texttt { in} \ \texttt { new} \ \type { C} (\overline { \expr { x} } ) \\
& \anf { t.f} & = & \texttt { let} \ \expr { x} = \anf { t} \ \texttt { in} \ \expr { x} .f \\
& \anf { t.\texttt { m} (\overline { t} )} & = & \texttt { let} \ \expr { x} = \anf { t} \ \texttt { in} \ \texttt { let} \ \overline { \expr { x} } = \anf { \overline { t} } \ \texttt { in} \ \expr { x} .\texttt { m} (\overline { \expr { x} } ) \\
& \anf { t_ 1 \elvis { } t_ 2} & = & \anf { t_ 1} \elvis { } \anf { t_ 2}
\end { array} $
2024-03-29 23:07:26 +00:00
\end { center}
\caption { ANF Transformation} \label { fig:anfTransformation}
\end { figure}
2024-03-28 02:40:39 +00:00
% $
% \begin{array}{lrcl|l}
% \hline
% & & & \textbf{Featherweight Java} & \textbf{A-Normal form} \\
% \text{Terms} & t & ::=
% & \expr{x}
% & \expr{x}
% \\
% & & \ \ |
% & \texttt{new} \ \type{C}(\overline{t})
% & \texttt{let}\ \overline{x} = \overline{t} \ \texttt{in}\ \texttt{new} \ \type{C}(\overline{x})
% \\
% & & \ \ |
% & t.f
% & \texttt{let}\ x = t \ \texttt{in}\ x.f
% \\
% & & \ \ |
% & t.\texttt{m}(\overline{t})
% & \texttt{let}\ x_1 = t \ \texttt{in}\ \texttt{let}\ \overline{x} = \overline{t} \ \texttt{in}\ x_1.\texttt{m}(\overline{x})
% \\
% & & \ \ |
% & t \elvis{} t
% & t \elvis{} t\\
% %
% \hline
% \end{array}
% $
2024-02-07 16:29:41 +00:00
% Each class type has a set of wildcard types $\overline{\Delta}$ attached to it.
% The type $\wctype{\overline{\Delta}}{C}{\ol{T}}$ defines a set of wildcards $\overline{\Delta}$,
% which can be used inside the type parameters $\ol{T}$.
2023-12-31 02:32:26 +00:00
\begin { figure} [tp]
2024-02-07 16:29:41 +00:00
\begin { center}
2023-12-31 02:32:26 +00:00
$ \begin { array } { l }
\typerule { S-Refl} \\
\begin { array} { @{ } c}
\Delta \vdash \type { T} <: \type { T}
\end { array}
\end { array} $
$ \begin { array } { l }
\typerule { S-Trans} \\
\begin { array} { @{ } c}
\Delta \vdash \type { S} <: \type { T} ' \quad \quad
\Delta \vdash \type { T} ' <: \type { T}
\\
\hline
\vspace * { -0.3cm} \\
\Delta \vdash \type { S} <: \type { T}
\end { array}
\end { array} $
$ \begin { array } { l }
\typerule { S-Upper} \\
\begin { array} { @{ } c}
\wildcard { X} { U} { L} \in \Delta \\
\vspace * { -0.9em} \\
\hline
\vspace * { -0.9em} \\
\Delta \vdash \type { X} <: \type { U}
\end { array}
\end { array} $
$ \begin { array } { l }
\typerule { S-Lower} \\
\begin { array} { @{ } c}
\wildcard { X} { U} { L} \in \Delta \\
\vspace * { -0.9em} \\
\hline
\vspace * { -0.9em} \\
\Delta \vdash \type { L} <: \type { X}
\end { array}
\end { array} $
\\ [1em]
$ \begin { array } { l }
\typerule { S-Extends} \\
\begin { array} { @{ } c}
2024-02-22 16:38:44 +00:00
\texttt { class} \ \exptype { C} { \overline { \type { X} \triangleleft \type { U} } } \triangleleft \type { N} \ \{ \ldots \} \\
2023-12-31 02:32:26 +00:00
\ol { X} \cap \text { dom} (\Delta ) = \emptyset
\\
\hline
\vspace * { -0.3cm} \\
2024-02-22 16:38:44 +00:00
\Delta \vdash \wctype { \Delta '} { C} { \ol { T} } <: \wcNtype { \Delta '} { [\ol { T} /\ol { X} ]\type { N} }
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
$ \begin { array } { l }
\typerule { S-Exists} \\
\begin { array} { @{ } c}
\Delta ', \Delta \vdash [\ol { T} /\ol { \type { X} } ]\ol { L} <: \ol { T} \quad \quad
\Delta ', \Delta \vdash \ol { T} <: [\ol { T} /\ol { \type { X} } ]\ol { U} \\
2024-02-07 16:29:41 +00:00
\text { fv} (\ol { T} ) \subseteq \text { dom} (\Delta , \Delta ') \quad
2024-04-03 19:01:21 +00:00
\text { dom} (\Delta ') \cap \text { fv} (\wcNtype { \ol { \wildcard { X} { U} { L} } } { N} ) = \emptyset
2023-12-31 02:32:26 +00:00
\\
\hline
\vspace * { -0.3cm} \\
2024-02-07 16:29:41 +00:00
\Delta \vdash \wcNtype { \Delta '} { [\ol { T} /\ol { X} ]\type { N} } <:
\wcNtype { \ol { \wildcard { X} { U} { L} } } { N}
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
2024-02-07 16:29:41 +00:00
\end { center}
2023-12-31 02:32:26 +00:00
\caption { Subtyping} \label { fig:subtyping}
\end { figure}
\begin { figure} [tp]
2024-01-29 17:39:18 +00:00
\begin { center}
2023-12-31 02:32:26 +00:00
$ \begin { array } { l }
\typerule { WF-Bot} \\
\begin { array} { @{ } c}
\Delta \vdash \bot \ \ok
\end { array}
\end { array} $
$ \begin { array } { l }
\typerule { WF-Top} \\
\begin { array} { @{ } c}
\Delta \vdash \ol { L} , \ol { U} \ \ok
\\
\hline
\vspace * { -0.3cm} \\
\Delta \vdash \overline { \wildcard { W} { U} { L} } .\texttt { Object}
\end { array}
\end { array} $
$ \begin { array } { l }
\typerule { WF-Var} \\
\begin { array} { @{ } c}
2024-01-29 17:39:18 +00:00
\wildcard { W} { U} { L} \in \Delta \quad \quad
2023-12-31 02:32:26 +00:00
\Delta \vdash \ol { L} , \ol { U} \ \ok
\\
\hline
\vspace * { -0.3cm} \\
\Delta \vdash \wildcard { W} { U} { L} \ \ok
\end { array}
\end { array} $
2024-01-29 17:39:18 +00:00
\\ [1em]
2023-12-31 02:32:26 +00:00
$ \begin { array } { l }
\typerule { WF-Class} \\
\begin { array} { @{ } c}
2024-01-29 17:39:18 +00:00
\Delta ' = \ol { \wildcard { W} { U} { L} } \quad \quad
\Delta , \Delta ' \vdash \ol { T} , \ol { L} , \ol { U} \ \ok \quad \quad
\Delta , \Delta ' \vdash \ol { L} <: \ol { U} \\
\Delta , \Delta ' \vdash \ol { T} <: [\ol { T} /\ol { X} ] \ol { U'} \quad \quad
2023-12-31 02:32:26 +00:00
\texttt { class} \ \exptype { C} { \ol { X \triangleleft U'} } \triangleleft \type { N} \ \{ \ldots \}
\\
\hline
\vspace * { -0.3cm} \\
\Delta \vdash \wctype { \ol { \wildcard { W} { U} { L} } } { C} { \ol { T} } \ \ok
\end { array}
\end { array} $
2024-01-29 17:39:18 +00:00
\end { center}
2023-12-31 02:32:26 +00:00
\caption { Well-formedness} \label { fig:well-formedness}
\end { figure}
\begin { figure} [tp]
2024-02-07 16:29:41 +00:00
\begin { center}
2023-12-31 02:32:26 +00:00
$ \begin { array } { l }
\typerule { T-Var} \\
\begin { array} { @{ } c}
2024-02-07 16:29:41 +00:00
\texttt { x} : \type { T} \in \Gamma
\\
\hline
\vspace * { -0.3cm} \\
\triangle | \Gamma \vdash \texttt { x} : \type { T}
\end { array}
\end { array} $ \hfill
$ \begin { array } { l }
\typerule { T-Field} \\
\begin { array} { @{ } c}
2024-03-18 13:57:56 +00:00
\Delta | \Gamma \vdash \expr { v} : \type { T} \quad \quad
\Delta \vdash \type { T} <: \wcNtype { } { N} \quad \quad
2024-02-07 16:29:41 +00:00
\textit { fields} (\type { N} ) = \ol { U\ f} \\
2023-12-31 02:32:26 +00:00
\hline
\vspace * { -0.3cm} \\
2024-03-18 13:57:56 +00:00
\Delta | \Gamma \vdash \expr { v} .\texttt { f} _ i : \type { U} _ i
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
\\ [1em]
2024-03-18 13:57:56 +00:00
% $\begin{array}{l}
% \typerule{T-Field}\\
% \begin{array}{@{}c}
% \Delta | \Gamma \vdash \texttt{e} : \type{T} \quad \quad
% \Delta \vdash \type{T} <: \wcNtype{\Delta'}{N} \quad \quad
% \textit{fields}(\type{N}) = \ol{U\ f} \\
% \Delta, \Delta' \vdash \type{U}_i <: \type{S} \quad \quad
% \text{dom}(\Delta') \subseteq \text{fv}(\type{N}) \quad \quad
% \Delta \vdash \type{S}, \wcNtype{\Delta'}{N} \ \ok
% \\
% \hline
% \vspace*{-0.3cm}\\
% \Delta | \Gamma \vdash \texttt{e}.\texttt{f}_i : \type{S}
% \end{array}
% \end{array}$
% \\[1em]
% $\begin{array}{l}
% \typerule{T-New}\\
% \begin{array}{@{}c}
% \Delta, \overline{\Delta} \vdash \exptype{C}{\ol{T}} \ \ok \quad \quad
% \text{fields}(\exptype{C}{\ol{T}}) = \overline{\type{U}\ f} \quad \quad
% \Delta | \Gamma \vdash \overline{t : \type{S}} \quad \quad
% \Delta \vdash \overline{\type{S}} <: \overline{\wcNtype{\Delta}{N}} \\
% \Delta, \overline{\Delta} \vdash \overline{\type{N}} <: \overline{\type{U}} \quad \quad
% \Delta, \overline{\Delta} \vdash \exptype{C}{\ol{T}} <: \type{T} \quad \quad
% \overline{\text{dom}(\Delta) \subseteq \text{fv}(\type{N})} \quad \quad
% \Delta \vdash \type{T}, \overline{\wcNtype{\Delta}{N}} \ \ok
% \\
% \hline
% \vspace*{-0.3cm}\\
% \triangle | \Gamma \vdash \texttt{new}\ \type{C}(\ol{t}) : \exptype{C}{\ol{T}}
% \end{array}
% \end{array}$
% \\[1em]
2023-12-31 02:32:26 +00:00
$ \begin { array } { l }
\typerule { T-New} \\
\begin { array} { @{ } c}
\Delta , \overline { \Delta } \vdash \exptype { C} { \ol { T} } \ \ok \quad \quad
2024-03-18 13:57:56 +00:00
\Delta \vdash \overline { \type { S} } <: \overline { \type { U} } \\
\Delta | \Gamma \vdash \overline { \expr { v} : \type { S} } \quad \quad
\text { fields} (\exptype { C} { \ol { T} } ) = \overline { \type { U} \ f}
2023-12-31 02:32:26 +00:00
\\
\hline
\vspace * { -0.3cm} \\
2024-03-18 13:57:56 +00:00
\triangle | \Gamma \vdash \texttt { new} \ \type { C} (\ol { v} ) : \exptype { C} { \ol { T} }
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
2024-03-18 13:57:56 +00:00
\hfill
% $\begin{array}{l}
% \typerule{T-Call}\\
% \begin{array}{@{}c}
% \Delta, \Delta', \overline{\Delta} \vdash \ol{\type{N}} <: [\ol{S}/\ol{X}]\ol{U} \quad \quad
% \generics{\ol{X \triangleleft U'}} \ol{U} \to \type{U} \in \Pi(\texttt{m}) \quad \quad
% \Delta, \Delta', \overline{\Delta} \vdash \ol{S} <: [\ol{S}/\ol{X}]\ol{U'}
% \\
% \Delta, \Delta', \overline{\Delta} \vdash \ol{S} \ \ok \quad \quad
% \Delta | \Gamma \vdash \texttt{e}, \ol{e} : \ol{T} \quad \quad
% \Delta \vdash \ol{T} <: \overline{\wcNtype{\Delta}{N}}
% \\
% \Delta \vdash \type{T}, \overline{\wcNtype{\Delta}{N}} \ \ok \quad \quad
% \Delta, \Delta', \overline{\Delta} \vdash [\ol{S}/\ol{X}]\type{U} <: \type{T} \quad \quad
% \text{dom}(\Delta') \subseteq \text{fv}(\type{N}) \quad \quad
% \overline{\text{dom}(\Delta) \subseteq \text{fv}(\type{N})}
% \\
% \hline
% \vspace*{-0.3cm}\\
% \Delta | \Gamma \vdash \texttt{e}.\texttt{m}(\ol{e}) : \type{T}
% \end{array}
% \end{array}$
% \\[1em]
2024-03-15 16:37:58 +00:00
$ \begin { array } { l }
\typerule { T-Call} \\
\begin { array} { @{ } c}
\generics { \ol { X \triangleleft U'} } \ol { U} \to \type { U} \in \Pi (\texttt { m} ) \quad \quad
2024-03-18 13:57:56 +00:00
\Delta \vdash \ol { S} <: [\ol { S} /\ol { X} ]\ol { U'}
2024-03-15 16:37:58 +00:00
\\
\Delta \vdash \ol { S} \ \ok \quad \quad
2024-03-18 13:57:56 +00:00
\Delta | \Gamma \vdash \expr { v} , \ol { v} : \ol { T} \quad \quad
2024-03-15 16:37:58 +00:00
\Delta \vdash \ol { T} <: [\ol { S} /\ol { X} ]\ol { U}
\\
\hline
\vspace * { -0.3cm} \\
2024-03-18 13:57:56 +00:00
\Delta | \Gamma \vdash \expr { v} .\texttt { m} (\ol { v} ) : \type { T}
2024-03-15 16:37:58 +00:00
\end { array}
\end { array} $
\\ [1em]
$ \begin { array } { l }
\typerule { T-Let} \\
\begin { array} { @{ } c}
2024-03-29 23:07:26 +00:00
\Delta | \Gamma \vdash \expr { t} _ 1 : \type { T} _ 1 \quad \quad
2024-03-15 16:37:58 +00:00
\Delta \vdash \type { T} _ 1 <: \wcNtype { \Delta '} { N}
\\
\Delta , \Delta ' | \Gamma , \expr { x} : \wcNtype { } { N} \vdash \expr { t} _ 2 : \type { T} _ 2 \quad \quad
\Delta , \Delta ' \vdash \type { T} _ 2 <: \type { T} \quad \quad
\text { dom} (\Delta ') \subseteq \text { fv} (\type { N} ) \quad \quad
\Delta \vdash \type { T} , \wcNtype { \Delta '} { N} \ \ok
\\
\hline
\vspace * { -0.3cm} \\
2024-03-29 23:07:26 +00:00
\Delta | \Gamma \vdash \texttt { let} \ \expr { x} = \expr { t} _ 1 \ \texttt { in} \ \expr { t} _ 2 : \type { T}
2024-03-15 16:37:58 +00:00
\end { array}
\end { array} $
\\ [1em]
2023-12-31 02:32:26 +00:00
$ \begin { array } { l }
\typerule { T-Elvis} \\
\begin { array} { @{ } c}
2024-02-07 16:29:41 +00:00
\triangle | \Gamma \vdash \texttt { t} : \type { T} _ 1 \quad \quad
\triangle | \Gamma \vdash \texttt { t} _ 2 : \type { T} _ 2 \quad \quad
\triangle \vdash \type { T} _ 1 <: \type { T} \quad \quad
\triangle \vdash \type { T} _ 2 <: \type { T} \quad \quad
\\
\hline
\vspace * { -0.3cm} \\
\triangle | \Gamma \vdash \texttt { t} _ 1 \ \texttt { ?:} \ \texttt { t} _ 2 : \type { T}
\end { array}
\end { array} $
\end { center}
\caption { Expression Typing} \label { fig:expressionTyping}
\end { figure}
\begin { figure}
\begin { center}
$ \begin { array } { l }
\typerule { T-Method} \\
\begin { array} { @{ } c}
2024-03-06 13:20:17 +00:00
(\type { T'} ,\ol { T} ) \to \type { T} \in \mathtt { \Pi } (\texttt { m} )\quad \quad
2024-02-07 16:29:41 +00:00
\triangle ' = \overline { \type { Y} : \bot .. \type { P} } \quad \quad
2024-02-07 17:26:41 +00:00
\triangle , \triangle ' \vdash \ol { P} , \type { T} , \ol { T} \ \ok \\
\text { dom} (\triangle ) = \ol { X} \quad \quad
2024-02-07 16:29:41 +00:00
%\texttt{class}\ \exptype{C}{\ol{X \triangleleft \_ }} \triangleleft \type{N} \ \{ \ldots \} \\
\mathtt { \Pi } | \triangle , \triangle ' | \ol { x : T} , \texttt { this} : \exptype { C} { \ol { X} } \vdash \texttt { e} : \type { S} \quad \quad
\triangle \vdash \type { S} <: \type { T}
2023-12-31 02:32:26 +00:00
\\
\hline
\vspace * { -0.3cm} \\
2024-02-07 17:26:41 +00:00
\mathtt { \Pi } | \triangle \vdash \texttt { m} (\ol { x} ) = \texttt { e} \ \ok \text { in C with } \generics { \ol { Y \triangleleft P} }
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
\\ [1em]
$ \begin { array } { l }
2024-02-07 16:29:41 +00:00
\typerule { T-Class} \\
2023-12-31 02:32:26 +00:00
\begin { array} { @{ } c}
2024-03-29 23:07:26 +00:00
\mathtt { \Pi } ' = \mathtt { \Pi } \cup \set { \texttt { m} : (\exptype { C} { \ol { X} } , \ol { T_ \texttt { m} } ) \to \type { T} _ \texttt { m} \mid \texttt { m} \in \ol { M} } \\
2024-03-06 13:20:17 +00:00
\mathtt { \Pi } '' = \mathtt { \Pi } \cup \set { \texttt { m} :
\generics { \ol { X \triangleleft \type { N} } , \ol { Y \triangleleft P} } (\exptype { C} { \ol { X} } ,\ol { T_ \texttt { m} } ) \to \type { T} _ \texttt { m} \mid \texttt { m} \in \ol { M} } \\
2024-02-07 16:29:41 +00:00
\triangle = \overline { \type { X} : \bot .. \type { U} } \quad \quad
\triangle \vdash \ol { U} , \ol { T} , \type { N} \ \ok \quad \quad
2024-02-07 17:26:41 +00:00
\mathtt { \Pi } ' | \triangle \vdash \ol { M} \ \ok \text { in C with} \ \generics { \ol { Y \triangleleft P} }
2023-12-31 02:32:26 +00:00
\\
\hline
\vspace * { -0.3cm} \\
2024-02-07 16:29:41 +00:00
\texttt { class} \ \exptype { C} { \ol { X \triangleleft U} } \triangleleft \type { N} \{ \ol { T\ f} ; \ol { M} \} : \mathtt { \Pi } ''
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
\\ [1em]
$ \begin { array } { l }
2024-02-07 16:29:41 +00:00
\typerule { T-Program} \\
2023-12-31 02:32:26 +00:00
\begin { array} { @{ } c}
2024-02-07 16:29:41 +00:00
\emptyset \vdash \texttt { L} _ 1 : \mathtt { \Pi } _ 1 \quad \quad
\mathtt { \Pi } _ 1 \vdash \texttt { L} _ 2 : \mathtt { \Pi } _ 1 \quad \quad
\ldots \quad \quad
\mathtt { \Pi } _ { n-1} \vdash \texttt { L} _ n : \mathtt { \Pi } _ n \quad \quad
2023-12-31 02:32:26 +00:00
\\
\hline
\vspace * { -0.3cm} \\
2024-02-07 16:29:41 +00:00
\vdash \ol { L} : \mathtt { \Pi } _ n
2023-12-31 02:32:26 +00:00
\end { array}
\end { array} $
2024-02-07 16:29:41 +00:00
\end { center}
\caption { Class and Method Typing rules} \label { fig:typing}
2023-12-31 02:32:26 +00:00
\end { figure}
2024-02-07 16:29:41 +00:00
\begin { figure}
$ \text { fields } ( \exptype { Object } { } ) = \emptyset $
\quad \quad
$ \begin { array } { l }
\typerule { F-Class} \\
\begin { array} { @{ } c}
\texttt { class} \ \exptype { C} { \ol { X \triangleleft \_ } } \triangleleft \type { N} \set { \ol { S\ f} ; \ol { M} } \quad \quad
\text { fields} ([\ol { T} /\ol { X} ]\type { N} ) = \ol { U\ g}
\\
\hline
\vspace * { -0.3cm} \\
\text { fields} (\exptype { C} { \ol { T} } ) = \ol { U\ g} , [\ol { T} /\ol { X} ]\ol { S\ f}
\end { array}
\end { array} $
2024-03-18 13:57:56 +00:00
\caption { Field access}
2024-02-07 16:29:41 +00:00
\end { figure}