1
0
mirror of https://github.com/dhil/phd-dissertation synced 2026-03-13 11:08:25 +00:00

Syntactic categories.

This commit is contained in:
2020-01-23 15:03:18 +00:00
parent 2c107f0234
commit 518739f291
2 changed files with 106 additions and 49 deletions

View File

@@ -105,10 +105,18 @@
\newcommand{\CompCat}{\CatName{Comp}} \newcommand{\CompCat}{\CatName{Comp}}
\newcommand{\ValCat}{\CatName{Val}} \newcommand{\ValCat}{\CatName{Val}}
\newcommand{\VarCat}{\CatName{Var}} \newcommand{\VarCat}{\CatName{Var}}
\newcommand{\TypCat}{\CatName{Type}} \newcommand{\ValTypeCat}{\CatName{TVal}}
\newcommand{\TyVarCat}{\CatName{TyVar}} \newcommand{\CompTypeCat}{\CatName{TComp}}
\newcommand{\PresenceCat}{\CatName{Presence}}
\newcommand{\TypeCat}{\CatName{Type}}
\newcommand{\TyVarCat}{\CatName{TVar}}
\newcommand{\KindCat}{\CatName{Kind}} \newcommand{\KindCat}{\CatName{Kind}}
\newcommand{\RowCat}{\RowCat} \newcommand{\RowCat}{\CatName{Row}}
\newcommand{\EffectCat}{\CatName{Effect}}
\newcommand{\TermCat}{\CatName{Term}}
\newcommand{\LabelCat}{\CatName{Label}}
\newcommand{\TyEnvCat}{\CatName{TyEnv}}
\newcommand{\KindEnvCat}{\CatName{KindEnv}}
%% %%
%% Lindley's array stuff. %% Lindley's array stuff.

View File

@@ -251,26 +251,42 @@ Section~\ref{sec:base-language-type-rules}.
\label{sec:base-language-types} \label{sec:base-language-types}
% %
\begin{figure} \begin{figure}
\begin{syntax} \begin{syntax}
\slab{Value types} &A,B &::= & A \to C % \slab{Value types} &A,B &::= & A \to C
\mid \alpha % \mid \alpha
\mid \forall \alpha^K.C % \mid \forall \alpha^K.C
\mid \Record{R} % \mid \Record{R}
\mid [R]\\ % \mid [R]\\
\slab{Computation types} % \slab{Computation types}
&C,D &::= & A \eff E \\ % &C,D &::= & A \eff E \\
\slab{Effect types} &E &::= & \{R\}\\ % \slab{Effect types} &E &::= & \{R\}\\
\slab{Row types} &R &::= & \ell : P;R \mid \rho \mid \cdot \\ % \slab{Row types} &R &::= & \ell : P;R \mid \rho \mid \cdot \\
\slab{Presence types} &P &::= & \Pre{A} \mid \Abs \mid \theta\\ % \slab{Presence types} &P &::= & \Pre{A} \mid \Abs \mid \theta\\
%\slab{Labels} &\ell & & \\ % %\slab{Labels} &\ell & & \\
% \slab{Types} &T &::= & A \mid C \mid E \mid R \mid P \\ % % \slab{Types} &T &::= & A \mid C \mid E \mid R \mid P \\
\slab{Kinds} &K &::= & \Type \mid \Row_\mathcal{L} \mid \Presence % \slab{Kinds} &K &::= & \Type \mid \Row_\mathcal{L} \mid \Presence
\mid \Comp \mid \Effect \\ % \mid \Comp \mid \Effect \\
\slab{Label sets} &\mathcal{L} &::=& \emptyset \mid \{\ell\} \uplus \mathcal{L}\\ % \slab{Label sets} &\mathcal{L} &::=& \emptyset \mid \{\ell\} \uplus \mathcal{L}\\
%\slab{Type variables} &\alpha, \rho, \theta& \\ % %\slab{Type variables} &\alpha, \rho, \theta& \\
\slab{Type environments} &\Gamma &::=& \cdot \mid \Gamma, x:A \\ % \slab{Type environments} &\Gamma &::=& \cdot \mid \Gamma, x:A \\
\slab{Kind environments} &\Delta &::=& \cdot \mid \Delta, \alpha:K % \slab{Kind environments} &\Delta &::=& \cdot \mid \Delta, \alpha:K
\end{syntax} \slab{Value types} &A,B \in \ValTypeCat &::= & A \to C
\mid \forall \alpha^K.C
\mid \Record{R} \mid [R]
\mid \alpha \\
\slab{Computation types\!\!}
&C,D \in \CompTypeCat &::= & A \eff E \\
\slab{Effect types} &E \in \EffectCat &::= & \{R\}\\
\slab{Row types} &R \in \RowCat &::= & \ell : P;R \mid \rho \mid \cdot \\
\slab{Presence types\!\!\!\!\!} &P \in \PresenceCat &::= & \Pre{A} \mid \Abs \mid \theta\\
\\
\slab{Types} &T \in \TypeCat &::= & A \mid C \mid E \mid R \mid P \\
\slab{Kinds} &K \in \KindCat &::= & \Type \mid \Comp \mid \Effect \mid \Row_\mathcal{L} \mid \Presence \\
\slab{Label sets} &\mathcal{L} \in \LabelCat &::=& \emptyset \mid \{\ell\} \uplus \mathcal{L}\\\\
\slab{Type environments} &\Gamma \in \TyEnvCat &::=& \cdot \mid \Gamma, x:A \\
\slab{Kind environments} &\Delta \in \KindEnvCat &::=& \cdot \mid \Delta, \alpha:K \\
\end{syntax}
\caption{Syntax of types, kinds, and their environments.} \caption{Syntax of types, kinds, and their environments.}
\label{fig:base-language-types} \label{fig:base-language-types}
\end{figure} \end{figure}
@@ -434,6 +450,21 @@ Kind and type environments are right-extended sequences of bindings. A
kind environment binds type variables to their kinds, whilst a type kind environment binds type variables to their kinds, whilst a type
environment binds term variables to their types. environment binds term variables to their types.
\paragraph{Type variable} The type structure has three syntactically
distinct type variables (the kinding system gives us five semantically
distinct notions of type variables). As we sometimes wish to refer
collectively to type variables, we define the set of type variables,
$\TyVarCat$, to be generated by:
%
\[
\TyVarCat \defas
\ba[t]{@{~}l@{~}l}
&\{ A \in \ValTypeCat \mid A \text{ has the form } \alpha \}\\
\cup &\{ R \in \RowCat \mid R \text{ has the form } \rho \}\\
\cup &\{ P \in \PresenceCat \mid P \text{ has the form } \theta \}
\ea
\]
% Value types comprise the function type $A \to C$, whose domain % Value types comprise the function type $A \to C$, whose domain
% is a value type and its codomain is a computation type $B \eff E$, % is a value type and its codomain is a computation type $B \eff E$,
% where $E$ is an effect type detailing which effects the implementing % where $E$ is an effect type detailing which effects the implementing
@@ -472,7 +503,8 @@ environment binds term variables to their types.
\slab{Computations} &M,N \in \CompCat &::= & V\,W \mid V\,A\\ \slab{Computations} &M,N \in \CompCat &::= & V\,W \mid V\,A\\
& &\mid& \Let\; \Record{\ell=x;y} = V \; \In \; N\\ & &\mid& \Let\; \Record{\ell=x;y} = V \; \In \; N\\
& &\mid& \Case\; V \{\ell~x \mapsto M; y \mapsto N\} \mid \Absurd^C~V\\ & &\mid& \Case\; V \{\ell~x \mapsto M; y \mapsto N\} \mid \Absurd^C~V\\
& &\mid& \Return~V \mid \Let \; x \revto M \; \In \; N & &\mid& \Return~V \mid \Let \; x \revto M \; \In \; N\\
\slab{Terms} &T \in \TermCat &::= & x \mid V \mid M
\end{syntax} \end{syntax}
\caption{Term syntax of \BCalc{}.} \caption{Term syntax of \BCalc{}.}
@@ -539,7 +571,7 @@ Values
% Polymorphic abstraction % Polymorphic abstraction
\inferrule*[Lab=\tylab{PolyLam}] \inferrule*[Lab=\tylab{PolyLam}]
{\typv{\Delta,\alpha : K;\Gamma}{M : C} \\ {\typv{\Delta,\alpha : K;\Gamma}{M : C} \\
\alpha \notin FTV(\Gamma) \alpha \notin \FTV(\Gamma)
} }
{\typv{\Delta;\Gamma}{\Lambda \alpha^K .\, M : \forall \alpha^K . \,C}} {\typv{\Delta;\Gamma}{\Lambda \alpha^K .\, M : \forall \alpha^K . \,C}}
\\ \\
@@ -619,46 +651,61 @@ Figure~\ref{fig:base-language-type-rules}. In each typing rule, we
implicitly assume that each type is well-kinded with respect to the implicitly assume that each type is well-kinded with respect to the
kinding environment $\Delta$. kinding environment $\Delta$.
\paragraph{Typing values} The \tylab{Var} rule states that a variable $x$ has \paragraph{Typing values} The \tylab{Var} rule states that a variable
type $A$ if $x$ is bound to $A$ in the type environment $\Gamma$. The $x$ has type $A$ if $x$ is bound to $A$ in the type environment
\tylab{Lam} rules states that a lambda value $(\lambda x.M)$ has type $\Gamma$. The \tylab{Lam} rules states that a lambda value
$A \to C$ if the computation $M$ has type $C$ assuming $x : A$. In the $(\lambda x.M)$ has type $A \to C$ if the computation $M$ has type $C$
\tylab{PolyLam} rule we make use of the set of \emph{free type assuming $x : A$. In the \tylab{PolyLam} rule we make use of the set
variables} (FTV). of \emph{free type variables} ($\FTV$) to ensure that we do not
inadvertently capture a free type variable from the context.
% %
We define FTV by mutual induction over type environments, $\Gamma$, We define $\FTV$ by mutual induction over type environments, $\Gamma$,
and the type structure: and the type structure, $T$, as follows.
% %
\[ \[
\ba[t]{@{~}l@{~~~~~~}c@{~}l} \ba[t]{@{~}l@{~~~~~~}c@{~}l}
\begin{eqs} \ba[t]{@{}l}
\begin{eqs}
\FTV &:& \ValTypeCat \to \TyVarCat\\
\FTV(\alpha) &\defas& \{\alpha\}\\ \FTV(\alpha) &\defas& \{\alpha\}\\
\FTV(\forall \alpha^K.C) &\defas& \FTV(C) \setminus \{\alpha\}\\ \FTV(\forall \alpha^K.C) &\defas& \FTV(C) \setminus \{\alpha\}\\
\FTV(A \to C) &\defas& \FTV(A) \cup \FTV(C)\\ \FTV(A \to C) &\defas& \FTV(A) \cup \FTV(C)\\
\FTV(A \eff E) &\defas& \FTV(A) \cup \FTV(E)\\ \FTV(A \eff E) &\defas& \FTV(A) \cup \FTV(E)\\
% \FTV(\{R\}) &\defas& \FTV(R)\\ \FTV(\{R\}) &\defas& \FTV(R)\\
% \FTV(\Record{R}) &\defas& \FTV(R)\\ \FTV(\Record{R}) &\defas& \FTV(R)\\
% \FTV([R]) &\defas& \FTV(R)\\ \FTV([R]) &\defas& \FTV(R)\\
% \FTV(l:P;R) &\defas& \FTV(P) \cup \FTV(R)\\ % \FTV(l:P;R) &\defas& \FTV(P) \cup \FTV(R)\\
% \FTV(\Pre{A}) &\defas& \FTV(A)\\ % \FTV(\Pre{A}) &\defas& \FTV(A)\\
% \FTV(\Abs) &\defas& \emptyset\\ % \FTV(\Abs) &\defas& \emptyset\\
% \FTV(\theta) &\defas& \{\theta\} % \FTV(\theta) &\defas& \{\theta\}
\end{eqs} & & \end{eqs}\ea & &
\begin{eqs} \begin{eqs}
\FTV([R]) &\defas& \FTV(R)\\ % \FTV([R]) &\defas& \FTV(R)\\
\FTV(\Record{R}) &\defas& \FTV(R)\\ % \FTV(\Record{R}) &\defas& \FTV(R)\\
\FTV(\{R\}) &\defas& \FTV(R)\\ % \FTV(\{R\}) &\defas& \FTV(R)\\
\FTV &:& \RowCat \to \TyVarCat\\
\FTV(l:P;R) &\defas& \FTV(P) \cup \FTV(R)\\ \FTV(l:P;R) &\defas& \FTV(P) \cup \FTV(R)\\
\end{eqs}\\\\ \FTV(\cdot) &\defas& \emptyset\\\\
\begin{eqs}
\FTV &:& \PresenceCat \to \TyVarCat\\
\FTV(\theta) &\defas& \{\theta\}\\ \FTV(\theta) &\defas& \{\theta\}\\
\FTV(\Abs) &\defas& \emptyset\\ \FTV(\Abs) &\defas& \emptyset\\
\FTV(\Pre{A}) &\defas& \FTV(A) \FTV(\Pre{A}) &\defas& \FTV(A)\\
\end{eqs} & & \end{eqs}\\\\
\begin{eqs} \multicolumn{3}{c}{\begin{eqs}
\FTV &:& \TyEnvCat \to \TyVarCat\\
\FTV(\cdot) &\defas& \emptyset\\ \FTV(\cdot) &\defas& \emptyset\\
\FTV(\Gamma,x : A) &\defas& \FTV(\Gamma) \cup \FTV(A) \FTV(\Gamma,x : A) &\defas& \FTV(\Gamma) \cup \FTV(A)
\end{eqs} \end{eqs}}
% \begin{eqs}
% \FTV(\theta) &\defas& \{\theta\}\\
% \FTV(\Abs) &\defas& \emptyset\\
% \FTV(\Pre{A}) &\defas& \FTV(A)
% \end{eqs} & &
% \begin{eqs}
% \FTV(\cdot) &\defas& \emptyset\\
% \FTV(\Gamma,x : A) &\defas& \FTV(\Gamma) \cup \FTV(A)
% \end{eqs}
\ea \ea
\] \]
% %
@@ -691,10 +738,12 @@ application $V\,A$ is well-typed whenever the abstractor term $V$ has
the polymorphic type $\forall \alpha^K.C$ and the type $A$ has kind the polymorphic type $\forall \alpha^K.C$ and the type $A$ has kind
$K$. This rule makes use of type substitution. We write $C[A/\alpha]$ $K$. This rule makes use of type substitution. We write $C[A/\alpha]$
to mean substitute some type $A$ for some type variable $\alpha$ in to mean substitute some type $A$ for some type variable $\alpha$ in
some type $C$. We define type substitution as a ternary function defined as follows some type $C$. We define type substitution as a ternary function
defined as follows.
% %
\[ \[
\begin{eqs} \begin{eqs}
-[-/-] &:& \TypeCat \times \TypeCat \times \TyVarCat \to \TypeCat\\
(A \to C)[B/\alpha] &\defas& A[B/\alpha] \to C[B/\alpha]\\ (A \to C)[B/\alpha] &\defas& A[B/\alpha] \to C[B/\alpha]\\
\alpha[B/\beta] &\defas& \begin{cases} \alpha[B/\beta] &\defas& \begin{cases}
B & \text{if } \alpha = \beta\\ B & \text{if } \alpha = \beta\\