Define operators used in the typing of patterns

Namely the type accepted by a pattern and the matching of a type against
a pattern

Fixes #9
This commit is contained in:
regnat 2017-04-26 17:09:02 +02:00
parent 7cb7a030d7
commit 11b4947f07
2 changed files with 47 additions and 1 deletions

View File

@ -81,12 +81,14 @@
slash-symbol = \sslash{}
}
\newcommand{\ofTypeP}[2]{\UseCollection{xfrac}{plainmath}\sfrac{#1}{#2}}
\newcommand{\matchType}[1]{\Lbag #1 \Rbag}
\newcommand{}{\Gamma}
\newcommand{}{\ensuremath{\tau}}
\newcommand{\σ}{\sigma}
\DeclareMathOperator\any{\textsc{Any}}
\newcommand{}{\lambda}
\newcommand{\recleq}{\sqsubsetleq}
\newcommand{\discrete}[2]{\left\{ #1, \ldots{}, #2 \right\}}
\newcommand{\discrete}[2]{\left\{ #1, .., #2 \right\}}
\newcommand{\pref}[1]{\ref{#1} at page~\pageref{#1}}

View File

@ -1,5 +1,49 @@
\subsection{The $\&-calculus$}
\subsubsection{Patterns}
The typing of patterns is inspired by~\cite{Fri04}: To every pattern $p$,
we associate a type $\Lbag p \Rbag$ which represents the type of all the
values accepted by the pattern. The exact definition of $\Lbag \_ \Rbag$ is
given in figure~\pref{typing::pattern-accept}.
We also define the matching $\ofTypeP{p}{}$ of a type $$ against a pattern
$p$ (in figure~\pref{typing::pattern-ty-match}).
The typing rules are given by the figures~\pref{typing::lambda-calculus},~\pref{typing::records} and~\pref{typing::operators}.
\begin{figure}
\begin{align*}
\matchType{x} &= \any \\
\matchType{q@x} &= \matchType{q} \\
\matchType{\{ f_1, \cdots, f_n \}} &= \{ \matchType{f_1}; \cdots \matchType{f_n}; \} \\
\matchType{l} &= l : \any \\
\matchType{l ? e} &= l : \any \vee \undef \\
\matchType{\text{Cons}(x_1, x_2)} &= \text{Cons}(\any, \any)
\end{align*}
\caption{Semantics of the $\matchType{\_}$ operator%
\label{typing::pattern-accept}}
\end{figure}
ii\begin{figure}
\begin{align*}
\ofTypeP{x}{} &= \sfrac{x}{} &\\
\ofTypeP{q@x}{} &= \sfrac{x}{}; \ofTypeP{q}{x} &\\
\ofTypeP{\{\}}{\{ x_1 ? c_1, \cdots, x_n ? c_n \}} &=%
\sfrac{x_1}{\mathcal{B}(c_1)}; \cdots; \sfrac{x_n}{\mathcal{B}(c_n)} &\\
\ofTypeP{\{ s_1 = _1; \cdots; s_m = _m; \}}{\{x_1 ? c_1, \cdots, x_n ? c_n, \textbf{\ldots}\}} &=%
\sfrac{x_1}{\mathcal{B}(c_1)}; \cdots; \sfrac{x_n}{\mathcal{B}(c_n)} &%
\text{ if } \forall (i,j) \in \discrete{1}{m} \times \discrete{1}{n}, s_i \neq s_j\\
\ofTypeP{\{ s = ;\}}{\{ x \}} &= \sfrac{x}{}; &\text{ if $s$ = $x$} \\
\ofTypeP{\{ s = ;\}}{\{ x ? c \}} &= \sfrac{x}{}; &\text{ if $s$ = $x$} \\
\ofTypeP{\{ s_1 = _1; \cdots; s_n = _n \}}{\{ x, f_1, \cdots, f_m \}} &=%
\sfrac{x}{}; \ofTypeP{\{ s_2 = _2; \cdots; s_n = _n \}}{\{ f_1, \cdots, f_m \}} &\text{ if $s_1$ = $x$} \\
\ofTypeP{\{ s_1 = _1; \cdots; s_n = _n \}}{\{ x ? c, f_1 \cdots, f_m \}} &=%
\sfrac{x}{}; \ofTypeP{\{ s_2 = _2; \cdots; s_n = _n \}}{\{ f_1, \cdots, f_m \}} &\text{ if $s_1$ = $x$} \\
\ofTypeP{\text{Cons}(_1, _2)}{\text{Cons}(x_1, x_2)} &= \sfrac{x_1}{_1}; \sfrac{x_2}{_2} &\\
\end{align*}
\caption{Semantics of $\ofTypeP{p}{}$%
\label{typing::pattern-ty-match}}
\end{figure}
\begin{figure}
\input{typing/lambdaCalculus}
\caption{Typing rules for the $\&-calculus$\label{typing::lambda-calculus}}