grammar: add typing annotations to patterns

And remove them from lambdas
This commit is contained in:
regnat 2017-05-11 07:30:24 +02:00
parent 864957720a
commit 51468d4d15
3 changed files with 30 additions and 25 deletions

View File

@ -37,6 +37,7 @@
\def\o/{\meta{o}}
\def\p/{\meta{p}}
\def\q/{\meta{q}}
\def\r/{\meta{r}}
\def\s/{\meta{s}}
\def\t/{\meta{t}}
\def\u/{\meta{u}}
@ -72,6 +73,7 @@
\newcommand{\quasiconst}[1]{\overset{#1}{\twoheadrightarrow}}
\DeclareMathOperator\dom{dom}
\DeclareMathOperator\deff{def}
\DeclareMathOperator\var{\mathcal{V}}
\newcommand{\orthsum}{\oplus^\bot}
\newcommand{\orthplus}{\diamond}
\newcommand{\subtype}{\leq}

View File

@ -3,12 +3,12 @@
<e> ::=
\x/ \| \c/
\alt \e/.\a/ \| \e/.\a/ or \e/
\alt $$\p/:.\e/ \| \e/ \e/
\alt $$\p/.\e/ \| \e/ \e/
\alt \{ \e/ = \e/ \}
\alt with \e/; \e/
\alt (\x/ := \e/ $\bm{\in}$ \t/) ? \e/ : \e/
\alt let \x/ = \e/; $\cdots{}$; \x/ = \e/; in \e/
\alt let rec \x/: = \e/; $\cdots{}$; \x/:/ = \e/; in \e/
\alt let rec \r/ = \e/; $\cdots{}$; \r/ = \e/; in \e/
\alt \o/
<o> ::= attrNames(\e/) \| listToAttrs(\e/)
@ -24,12 +24,14 @@
\alt nil
\alt $\cdots{}$
<p> ::= \q/ \| \q/@\x/ \| \x/
<p> ::= \q/ \| \q/@\x/ \| \r/
<q> ::= \{ \f/, $\cdots{}$, \f/ \} \| \{ \f/, $\cdots{}$, \f/ , \ldots{}\}
\alt Cons(\x/, \x/) \| nil
\alt \c/
\alt Cons(\r/, \r/) \| nil
\alt \q/:
<f> ::= \x/ \| \x/ ? \c/
<r> ::= \x/ | \x/:
<f> ::= \r/ \| \r/ ? \c/
\end{grammar}

View File

@ -36,47 +36,48 @@ figure~\pref{fig:semantics:nix-light:patterns}
\end{figure}
\begin{figure}
% TODO Rewrite in a clear way. Exlpain the fact that we can reordonate stuff because we got a
% commutative monoid.
\begin{tabular}{rl}
\eqdefa{$\sfrac{x:t}{e}$}{$\sfrac{x}{e}$}{}
\eqdefa{$\sfrac{x}{e}$}{$\sfrac{x}{e}$}{}
\eqdefa{$\sfrac{q@x}{e}$}{$\sfrac{x}{e}; \sfrac{q}{x}$}{}
\eqdefa{$\sfrac{\{\}}{\{ x_1 ? c_1, \cdots, x_n ? c_n \}}$}{%
$\sfrac{x_1}{c_1}; \cdots; \sfrac{x_n}{c_n}$}{}
\eqdefa{$\sfrac{q@x}{e}$}{$\sfrac{x}{e}; \sfrac{q}{e}$}{}
\eqdefa{$\sfrac{q:t}{e}$}{$\sfrac{q}{e}$}{}
\eqdefa{$\sfrac{\{\}}{\{ r_1 ? c_1, \cdots, r_n ? c_n \}}$}{%
$\sfrac{r_1}{c_1}; \cdots; \sfrac{r_n}{c_n}$}{}
\eqdefa{%
$\sfrac{%
\{ s_1 = e_1; \cdots; s_m = e_m; \}%
}{%
\{x_1 ? c_1, \cdots, x_n ? c_n, \textbf{\ldots}\}%
\{r_1 ? c_1, \cdots, r_n ? c_n, \textbf{\ldots}\}%
}$%
}{%
$\sfrac{x_1}{c_1}; \cdots; \sfrac{x_n}{c_n}$%
$\sfrac{r_1}{c_1}; \cdots; \sfrac{r_n}{c_n}$%
}{%
if %
$\forall (i,j) \in \discrete{1}{m} \times \discrete{1}{n}, s_i \neq s_j$%
$\forall (i,j) \in \discrete{1}{m} \times \discrete{1}{n}, s_i \neq \var(r_j)$%
}
\eqdefa{$\sfrac{\{ s = e;\}}{\{ x \}}$}{$\sfrac{x}{e}$}{if $s = x$}
\eqdefa{$\sfrac{\{ s = e;\}}{\{ x ? c \}}$}{$\sfrac{x}{e}$}{if $s = x$}
\eqdefa{$\sfrac{\{ s = e;\}}{\{ r \}}$}{$\sfrac{r}{e}$}{if $s = \var(r)$}
\eqdefa{$\sfrac{\{ s = e;\}}{\{ r ? c \}}$}{$\sfrac{r}{e}$}{if $s = \var(r)$}
\eqdefa{$%
\sfrac{\{ s_1 = e_1; \cdots; s_n = e_n \}}{\{ x, f_1, \cdots, f_m \}}%
\sfrac{\{ s_1 = e_1; \cdots; s_n = e_n \}}{\{ r, f_1, \cdots, f_m \}}%
$}{$%
\sfrac{x}{e};%
\sfrac{r}{e};%
\sfrac{\{ s_2 = e_2; \cdots; s_n = e_n \}}{\{ f_1, \cdots, f_m \}}%
$}{if $s_1 = x$}
$}{if $s_1 = \var(r)$}
\eqdefa{
$\sfrac{%
\{ s_1 = e_1; \cdots; s_n = e_n \}}%
{\{ x ? c, f_1 \cdots, f_m \}}$%
{\{ r ? c, f_1 \cdots, f_m \}}$%
}{%
$\sfrac{x}{e};%
$\sfrac{r}{e};%
\sfrac{\{ s_2 = e_2; \cdots; s_n = e_n \}}%
{\{ f_1, \cdots, f_m \}}$%
}{if $s_1 = x$}
}{if $s_1 = \var(r)$}
\eqdefa{%
$\sfrac{\text{Cons}(e_1, e_2)}{\text{Cons}(x_1, x_2)}$%
}{$\sfrac{x_1}{e_1}; \sfrac{x_2}{e_2}$}{}
$\sfrac{\text{Cons}(e_1, e_2)}{\text{Cons}(r_1, r_2)}$%
}{$\sfrac{r_1}{e_1}; \sfrac{r_2}{e_2}$}{}
\end{tabular}
Where we define $\var(r)$ as $\var(x) = \var(x:t) = x$
\caption{Semantic of the pattern-matching in nix-light\label{fig:semantics:nix-light:patterns}}
\end{figure}