on master help sign in
Added unelaboration definition
3eabe79Edwin Brady
impl-paper/delab.tex+92
@@ -24,6 +24,98 @@ primarily \emph{erasing} information.
24
24
25\subsection{From \TT{} to \Idris{}}
25\subsection{From \TT{} to \Idris{}}
26
26
27+We define a meta-operation $\uninterp{\vt}$, which converts a \TT{} expression
28+$\vt$ to an \Idris{} expression which would elaborate to $\vt$:
29+
30+\DM{
31+\AR{
32+\begin{array}{rl}
33+\uninterp{\vx} &\mq\:\vx\\
34+\uninterp{\vc} &\mq\:\vc\\
35+\uninterp{\vx\;\ta} &\mq\:\vx\;(\vec{\MO{Impl}}\:\vx\:\ta) \\
36+\uninterp{\vf\:\va} &\mq\:\uninterp{\vf}\:\uninterp{\va}\\
37+\uninterp{\lam{\vx}{\vT}\SC\ve} &\mq \:\ilam{\vx}\uninterp{\ve} \\
38+\uninterp{\all{\vx}{\vT}\SC\ve} &\mq \:\piexp{\vx}{\uninterp{\vT}}\uninterp{\ve} \\
39+\uninterp{\LET\:\vx\defq\vt\Hab\vT\SC\ve} &\mq
40+\ilet{\vx}{\uninterp{\vt}}\uninterp{\ve}\\
41+\end{array}
42+\medskip\\
43+\begin{array}{rll}
44+\MO{Impl}\:\vx\:\va_i\:\mq
45+&
46+\iarg{\vn}{\ttinterp{\va_i}}&
47+\mbox{(if the $i$th argument to $\vx$ is implicit argument $\vn$)}\\
48+& \carg{\ttinterp{\va_i}} &
49+\mbox{(if the $i$th argument to $\vx$ is a constraint argument)}\\
50+& \ttinterp{\va_i} & \mbox{(otherwise)}
51+\end{array}
52+}
53+}
54+
55+\noindent
56+This is mostly a straightforward
57+traversal of the \TT{} expression, translating directly to an \Idris{} equivalent.
58+The interesting case is for applications of named functions,
59+$\uninterp{\vx\:\ta}$, where the arguments are translated to either implicit,
60+constraint or explicit arguments according to the definition of $\vx$.
61+Since only type declarations are allowed to have implicit or constraint arguments,
62+and $\uninterp{\cdot}$ translates \emph{expressions},
63+all function types are assumed to take explicit arguments.
64+
65+We also define an operation $\MO{Unelab}$, which translates \TT{} declarations
66+to corresponding \Idris{} declarations. This generates data declarations and
67+pattern matching definitions only --- it makes no attempt to reconstruct
68+\texttt{class}
69+or \texttt{instance} declarations, or rebuild \texttt{case} expressions.
70+First, we define the reverse elaboration of type declarations, which must reconstruct
71+which arguments are implicit or constraint arguments:
72+
73+\DM{
74+\AR{
75+\begin{array}{l}
76+\MO{UnelabType}\:(\vx\Hab\vt)\:\mq\:\vx\Hab\MO{UnelabTyDecl}\:0\:\vt
77+\end{array}
78+\medskip\\
79+\begin{array}{ll}
80+\MO{UnelabTyDecl}\:\vi\:(\all{\vx}{\vT}\SC\ve)
81+\mq & \piimp{\vx}{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
82+ & \hg\mbox{(if the $i$th argument to $\vx$ is an implicit argument)} \\
83+ & \piconst{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
84+ & \hg\mbox{(if the $i$th argument to $\vx$ is a constraint argument)} \\
85+ & \piexp{\vx}{\uninterp{\vT}}(\MO{UnelabTyDecl}\:(\vi+1)\:\ve) \\
86+ & \hg\mbox{(otherwise)} \\
87+\end{array}
88+}
89+}
90+
91+\noindent
92+Using this, we define $\MO{Unelab}$ for top level declarations. For pattern
93+matching clauses, we reverse elaborate as follows, discarding the explicit
94+pattern variable bindings and applying $\MO{UnelabType}$ to reconstruct
95+the type declaration:
96+
97+\DM{
98+\AR{
99+\MO{Unelab}\:(\vx\Hab\vt)\:\mq\:\MO{UnelabType}\:(\vx\Hab\vt)\\
100+\MO{Unelab}\:(\pat{\tx}{\tU}\SC\FN{f}\:\tts\:=\:\ve)
101+\:\mq\:\uninterp{\FN{f}\:\tts}\:=\:\uninterp{\ve}
102+}
103+}
104+
105+\noindent
106+For data type declarations, we unelaborate as follows, applying $\MO{UnelabType}$
107+for each of the top level type declarations:
108+
109+\DM{
110+\AR{
111+\MO{Unelab}\:(\Data\;\TC{T}\:(\tx\Hab\ttt)\Hab\vT\;\Where\;\vec{\VV{cons}})
112+\:\\
113+\hg\hg\mq\:\idata\:\MO{UnelabType}\:(\TC{T}\Hab\all{\tx}{\ttt}\SC\vT)\:\iwhere\:
114+(\vec{\MO{UnelabType}}\:\vec{\VV{cons}})
115+}
116+}
117+
118+
27\subsection{Elaboration Properties}
119\subsection{Elaboration Properties}
28
120
29\todo[inline]{
121\todo[inline]{
impl-paper/elaboration.tex+13−6
@@ -1,5 +1,5 @@
1\newcommand{\ttinterp}[1]{\mathcal{E}\interp{#1}}
1\newcommand{\ttinterp}[1]{\mathcal{E}\interp{#1}}
2−\newcommand{\uninterp}[1]{\mathcal{U}\interp{#1}}
2+\newcommand{\uninterp}[1]{\mathcal{T}\interp{#1}}
3
3
4\section{Elaborating \Idris{}}
4\section{Elaborating \Idris{}}
5
5
@@ -575,9 +575,14 @@ a Coq proof script.
575\medskip\\
575\medskip\\
576\begin{array}{rll}
576\begin{array}{rll}
577\vt ::= & \ve & (\mbox{expression}) \\
577\vt ::= & \ve & (\mbox{expression}) \\
578−\mid & \piimp{\vx}{\vt}\vt & (\mbox{implicit function space}) \\
579\mid & \piexp{\vx}{\vt}\vt & (\mbox{explicit function space}) \\
578\mid & \piexp{\vx}{\vt}\vt & (\mbox{explicit function space}) \\
579+\end{array}
580+\medskip\\
581+\begin{array}{rll}
582+\VV{declty} ::= & \ve & (\mbox{expression}) \\
583+\mid & \piexp{\vx}{\vt}\VV{declty} & (\mbox{explicit function space}) \\
584+\mid & \piimp{\vx}{\vt}\VV{declty} & (\mbox{implicit function space}) \\
580−\mid & \VV{constr}\;\vt & (\mbox{constrained type}) \\
585+\mid & \VV{constr}\;\VV{declty} & (\mbox{constrained type}) \\
581\end{array}
586\end{array}
582\medskip\\
587\medskip\\
583\begin{array}{rll}
588\begin{array}{rll}
@@ -591,7 +596,7 @@ a Coq proof script.
591\FFIG{
596\FFIG{
592\AR{
597\AR{
593\begin{array}{rll}
598\begin{array}{rll}
594−\vd ::= & \ihab{\vx}{\vt} & (\mbox{type declaration}) \\
599+\vd ::= & \ihab{\vx}{\VV{declty}} & (\mbox{type declaration}) \\
595\mid & \VV{pclause} & (\mbox{pattern clause}) \\
600\mid & \VV{pclause} & (\mbox{pattern clause}) \\
596\mid & \VV{ddecl} & (\mbox{data type declaration}) \\
601\mid & \VV{ddecl} & (\mbox{data type declaration}) \\
597\mid & \VV{cdecl} & (\mbox{class declaration}) \\
602\mid & \VV{cdecl} & (\mbox{class declaration}) \\
@@ -609,8 +614,8 @@ a Coq proof script.
609\end{array}
614\end{array}
610&
615&
611\begin{array}{rll}
616\begin{array}{rll}
612−\VV{ddecl} ::= & \idata\;\ihab{\vx}{\vt}\;\iwhere\;\vec{\VV{con}}\\
617+\VV{ddecl} ::= & \idata\;\ihab{\vx}{\VV{declty}}\;\iwhere\;\vec{\VV{con}}\\
613−\VV{con} ::= & \ihab{\vx}{\vt}\\
618+\VV{con} ::= & \ihab{\vx}{\VV{declty}}\\
614\medskip\\
619\medskip\\
615\VV{cdecl} ::= & \iclass\;[\VV{constr}]\;\vx\;(\ihab{\tx}{\ttt})\;\iwhere\;\td
620\VV{cdecl} ::= & \iclass\;[\VV{constr}]\;\vx\;(\ihab{\tx}{\ttt})\;\iwhere\;\td
616\\
621\\
@@ -629,6 +634,8 @@ tuple syntax, \texttt{do}-notation or infix operators --- and with implicit
629arguments in types bound explicitly
634arguments in types bound explicitly
630(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\:\va\:\vn$
635(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\:\va\:\vn$
631instead of simply $\Vect\:\va\:\vn$).
636instead of simply $\Vect\:\va\:\vn$).
637+Note that we separate implicit and type constraint bindings, to ensure that they
638+only appear in top level declarations.
632It is in general straightforward to
639It is in general straightforward to
633convert full \Idris{} to \IdrisM{} --- syntactic sugar is implemented by a
640convert full \Idris{} to \IdrisM{} --- syntactic sugar is implemented by a
634direct source transformation, and implicit arguments can be identified as the names
641direct source transformation, and implicit arguments can be identified as the names
impl-paper/typechecking.tex+1−1
@@ -42,7 +42,7 @@ inferred by the machine~\cite{pollack1990implicit}.
42 \mid & \vb\SC\:\vt & (\mbox{binding}) &
42 \mid & \vb\SC\:\vt & (\mbox{binding}) &
43 \mid & \all{\vx}{\vt} & (\mbox{function space}) \\
43 \mid & \all{\vx}{\vt} & (\mbox{function space}) \\
44
44
45− \mid & \vt\:\vt & (\mbox{application}) &
45+ \mid & \vt\;\vt & (\mbox{application}) &
46% \mid & \pat{\vx}{\vt} & (\mbox{pattern variable}) \\
46% \mid & \pat{\vx}{\vt} & (\mbox{pattern variable}) \\
47% & & &
47% & & &
48% \mid & \pty{\vx}{\vt} & (\mbox{pattern type}) \\
48% \mid & \pty{\vx}{\vt} & (\mbox{pattern type}) \\