[WIP] Refactor everything into one big document

This commit is contained in:
regnat 2017-04-11 12:01:24 +02:00
parent 241bdd5e17
commit d25edab8f9
8 changed files with 173 additions and 126 deletions

33
combined/main.tex Normal file
View File

@ -0,0 +1,33 @@
\input{common/header.tex}
\title{A type system for nix}
\begin{document}
\maketitle
In order to lighten the type system, we will not work on the full nix language
(presented in section~\ref{sec:nix-grammar}), but on a simplified version
called nix-light (roughly a subset of the original one) that we also presents
in this document.
We also present a compilation from nix to nix-light.
\section{grammar}
\input{grammar/grammar}
\section{semantics}
\subsection{nix-light semantics}
\input{semantics/semantics}
\subsection{From nix to nix-light}
\todo{Write the semantic of the compilation}
\section{typing}
\todo{Finish and include the typing rules}
\todos{}
\end{document}

View File

@ -86,3 +86,5 @@
\newcommand{\σ}{\sigma}
\newcommand{\recleq}{\sqsubsetleq}
\newcommand{\discrete}[2]{\left\{ #1, \ldots{}, #2 \right\}}
\newcommand{\pref}[1]{\ref{#1} at page~\pageref{#1}}

36
grammar/expressions.tex Normal file
View File

@ -0,0 +1,36 @@
\begin{grammar}
\bfseries
<e> ::=
\x/ \| \c/
\alt \e/.\a/ \| \e/.\a/ or \e/
\alt \p/:\e/ \| \e/ \e/
\alt \{ \e/ = \e/; \}
\alt with \e/; \e/
\alt (\e/ $\bm{\in}$ \t/) ? \e/ : \e/
\alt let \x/ = \e/; $\cdots{}$; \x/ = \e/; in \e/
\alt \o/
<o> ::= attrNames(\e/) \| listToAttrs(\e/)
\alt \e/ + \e/ \| \e/ $\orthplus$ \e/ \| \e/ \textbackslash \e/
\alt deepSeq(\e/, \e/) \| seq(\e/, \e/)
\alt functionArgs(\e/)
% Maybe this can be typed as a function, but it is rather unlikely
\alt Cons(\e/, \e/)
<a> ::= \b/. $\cdots{}$ .\b/
<b> ::= \$\{\e/\} \| \meta{l}
<c> ::= \meta{s} \| \meta{i} \| $\cdots{}$
\alt nil
\alt $\cdots{}$
<p> ::= \q/ \| \q/@\x/ \| \x/
<q> ::= \{ \f/, $\cdots{}$, \f/ \} \| \{ \f/, $\cdots{}$, \f/ , \ldots{}\}
\alt Cons(\x/, \x/) \| nil
\alt \c/
<f> ::= \x/ \| \x/ ? \e/
\end{grammar}

View File

@ -1,61 +1,26 @@
\input{common/header}
\subsection{Nix grammar}
\label{sec:nix-grammar}
\title{Nix simplified grammar}
\begin{document}
\todo{Write the nix grammar}
\maketitle{}
\subsection{nix-light}
\label{sec:nix-light-grammar}
\section{expressions}
The grammar of nix-light is given in the
figures~\pref{grammar::expressions},~\pref{grammar::values}
and~\pref{grammar::types}.
\begin{grammar}
\bfseries
<e> ::=
\x/ \| \c/
\alt \e/.\a/ \| \e/.\a/ or \e/
\alt \p/:\e/ \| \e/ \e/
\alt \{ \e/ = \e/; \}
\alt with \e/; \e/
\alt (\e/ $\bm{\in}$ \t/) ? \e/ : \e/
\alt let \x/ = \e/; $\cdots{}$; \x/ = \e/; in \e/
\alt \o/
\begin{figure}[h]
\input{grammar/expressions}
\caption{\label{grammar::expressions}The nix-light grammar for expressions}
\end{figure}
<o> ::= attrNames(\e/) \| listToAttrs(\e/)
\alt \e/ + \e/ \| \e/ $\orthplus$ \e/ \| \e/ \textbackslash \e/
\alt deepSeq(\e/, \e/) \| seq(\e/, \e/)
\alt functionArgs(\e/)
% Maybe this can be typed as a function, but it is rather unlikely
\alt Cons(\e/, \e/)
\begin{figure}[h]
\input{grammar/values}
\caption{\label{grammar::values}The nix-light grammar for values}
\end{figure}
<a> ::= \b/. $\cdots{}$ .\b/
<b> ::= \$\{\e/\} \| \meta{l}
<c> ::= \meta{s} \| \meta{i} \| $\cdots{}$
\alt nil
\alt $\cdots{}$
<p> ::= \q/ \| \q/@\x/ \| \x/
<q> ::= \{ \f/, $\cdots{}$, \f/ \} \| \{ \f/, $\cdots{}$, \f/ , \ldots{}\}
\alt Cons(\x/, \x/) \| nil
\alt \c/
<f> ::= \x/ \| \x/ ? \e/
\end{grammar}
The grammar for types (\t/) is given in the \texttt{type-system} document.
\section{values}
\begin{grammar}
\bfseries
<v> ::=
\c/
\alt \p/:\e/
\alt \{ \v/ = \e/; \} $\orthplus \cdots{} \orthplus$ \{ \v/ = \e/; \}
\alt Cons(\e/, \e/) \| nil
\end{grammar}
\end{document}
\begin{figure}[h]
\input{grammar/types}
\caption{\label{grammar::types}The nix-light grammar for types}
\end{figure}

19
grammar/types.tex Normal file
View File

@ -0,0 +1,19 @@
\begin{grammar}
\bfseries
<t> ::= \c/ \| \t/ $\bm{\rightarrow}$ \t/
\alt \t/ $\bm{\vee}$ \t/ \| \t/ $\bm{\wedge}$ \t/ \| \t/ $\bm{\backslash}$ \t/
\alt [\meta{R}]
\alt \{ \s/ = \u/; \ldots{}; \s/ = \u/; _ = \u/ \}
<u> ::= \t/ \| ?\t/
<R> ::= \t/ \| \meta{R^{\bm{+}}} \| \meta{R}?
\| \meta{R} $\bm{\vee}$ \meta{R} \| \meta{R} $\bm{\wedge}$ \meta{R}
<> ::= \t/ % No polymorphism for now
\end{grammar}
We write \textbf{\{ \s/ = \u/; \ldots{}; \s/ = \u/; \}} as syntactic
sugar for \textbf{\{ \s/ = \u/; \ldots{}; \s/ = \u/; _ = $\undef$ \}}, and
\textbf{\{ \s/ = \u/; \ldots{}; \s/ = \u/; .. \}} as syntactic sugar for
\textbf{\{ \s/ = \u/; \ldots{}; \s/ = \u/; _ = \textmd{\emph{Any}} \}})

9
grammar/values.tex Normal file
View File

@ -0,0 +1,9 @@
\begin{grammar}
\bfseries
<v> ::=
\c/
\alt \p/:\e/
\alt \{ \v/ = \e/; \} $\orthplus \cdots{} \orthplus$ \{ \v/ = \e/; \}
\alt Cons(\e/, \e/) \| nil
\end{grammar}

View File

@ -1,14 +1,12 @@
\input{common/header}
The reduction rules are presented in figure~\pref{fig:semantics:nix-light} and
the evaluation contexts in
figure~\pref{fig:semantics:nix-light:reduction-contexts}.
\title{Nix simplified semantics}
The rules for the pattern-matching are in
figure~\pref{fig:semantics:nix-light:patterns}
\begin{document}
\maketitle{}
\section{Reduction rules}
\begin{tabular}{rl}
\begin{figure}
\begin{tabular}{rl}
\dstepa{v.s}{e}{if $\vdash v : \{ e : \lnot\undef; .. \}$ and v(s) = e}
\dstepa{v.s or e'}{e}{if $\vdash v : \{ e : \lnot\undef; .. \}$ and v(s) = e}
\dstepa{v.s or e'}{e'}{if $\vdash v : \lnot\{ e : \lnot\undef; .. \}$}
@ -34,13 +32,15 @@
[ \\ \assign{\xone}{r.x'_1}; \ldots{}; \assign{\xn}{r.x'_n} \\ ]
}
}{}
\end{tabular}
\end{tabular}
\caption{Nix-light reduction rules\label{fig:semantics:nix-light}}
\end{figure}
\section{Pattern matching}
\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}
\begin{tabular}{rl}
\eqdefa{\assignp{q@x}{e}}{\assign{x}{e}; \assignp{q}{e}}{}
\eqdefa{\assignp{(\{ x \} \orthplus q)}{(\{ x = e; \} \orthplus v)}}{\assignp{x}{e}; \assignp{q}{v}}{}
\eqdefa{\assignp{(\{ x ? e' \} \orthplus q)}{(\{ x = e; \} \orthplus v)}}{\assignp{x}{e}; \assignp{q}{v}}{}
@ -48,11 +48,12 @@
\eqdefa{\assignp{\{\}}{\{ \}}}{ø}{}
\eqdefa{\assignp{\{ .. \}}{v}}{ø}{}
\eqdefa{\assignp{Cons(x, x')}{Cons(e, e')}}{\assign{x}{e}; \assign{x'}{e'}}{}
\end{tabular}
\end{tabular}
\caption{Semantic of the pattern-matching in nix-light\label{fig:semantics:nix-light:patterns}}
\end{figure}
\section{Reduction contexts}
\begin{grammar}
\begin{figure}
\begin{grammar}
\bfseries
<E> ::= [] \| \meta{E e}
\alt \meta{E.w} \| \meta{E.w} or \meta{e} \| \meta{v.F} \| \meta{v.F} or \meta{e}
@ -60,7 +61,6 @@
\alt with \E/; \e/ | if \E/ then \e/ else \e/
<F> ::= \E/.\a/ \| \v/.\meta{F}
\end{grammar}
\end{document}
\end{grammar}
\caption{Reduction contexts for nix-light\label{fig:semantics:nix-light:reduction-contexts}}
\end{figure}

View File

@ -7,25 +7,8 @@
\maketitle{}
\section{Types}
\begin{grammar}
\bfseries
<t> ::= \c/ \| \t/ $\bm{\rightarrow}$ \t/
\alt \t/ $\bm{\vee}$ \t/ \| \t/ $\bm{\wedge}$ \t/ \| \t/ $\bm{\backslash}$ \t/
\alt [\meta{R}]
\alt \{ \s/ = \u/; \ldots{}; \s/ = \u/; _ = \u/ \}
<u> ::= \t/ \| ?\t/
<R> ::= \t/ \| \meta{R^{\bm{+}}} \| \meta{R}?
\| \meta{R} $\bm{\vee}$ \meta{R} \| \meta{R} $\bm{\wedge}$ \meta{R}
<> ::= \t/ % No polymorphism for now
\end{grammar}
\textbf{\{ \s/ = \u/; \ldots{}; \s/ = \u/; \}} (\emph{resp}. \textbf{\{ \s/ =
\u/; \ldots{}; \s/ = \u/; .. \}}) is syntactic sugar for \textbf{\{ \s/ = \u/;
\ldots{}; \s/ = \u/; _ = $\undef$ \}} (\emph{resp}. \textbf{\{ \s/ = \u/;
\ldots{}; \s/ = \u/; _ = \textmd{\emph{Any}} \}})
\include{grammar/types}
\section{Typing rules}
\subsection{$\lambda\&$-calculus}