Commit 2091db6b authored by Michael Hanus 's avatar Michael Hanus
Browse files

Section about lambda lifting updated

parent c1070076
% $Id: report.tex,v 1.1 1999/07/21 12:29:41 hanus Exp hanus $
% $Id: report.tex,v 1.2 1999/07/21 15:46:55 hanus Exp hanus $
% $Log: report.tex,v $
% Revision 1.2 1999/07/21 15:46:55 hanus
% Section on lambda lifting transformation added
%
% Revision 1.1 1999/07/21 12:29:41 hanus
% Initial revision
%
......@@ -2602,7 +2605,7 @@ which shows the different messages sent to the account process.
\index{prelude}
This section contains the standard prelude for Curry programs.\footnote{%
The definition is will be extended in a later version.}
The definition will be extended in a later version.}
This prelude will be imported to every Curry program,
i.e., the names declared in the prelude cannot be redefined.
\startprog
......@@ -3221,8 +3224,8 @@ end
\por \term{(} Expr \term{)} \marg{\mbox{\it parenthesized expression}}
\por \term{(} \seq{Expr}{,}{n} \term{)} \marg{\mbox{\it tuple, $n > 1$}}
\por \term{[} \seq{Expr}{,}{n} \term{]}\marg{\mbox{\it list, $n\geqslant 0$}}
\por \term{(} Expr InfixOpID \term{)} \marg{\mbox{\it left section}}
\por \term{(} InfixOpID Expr \term{)} \marg{\mbox{\it right section}}
\por \term{(} Expr InfixOpID \term{)} \marg{\mbox{\it left section}\index{section}\index{section!left}\index{left section}}
\por \term{(} InfixOpID Expr \term{)} \marg{\mbox{\it right section}\index{section}\index{section!right}\index{right section}}
end
\production QTypeConstrID
......@@ -4151,30 +4154,38 @@ explicit support for local declarations, provided that
they satisfy the operational meaning described in the following.
The elimination of local function and pattern declarations is done
in three steps:
by the following steps which are subsequently described in more detail:
\begin{enumerate}
\item Eliminate sections and lambda abstractions
\item Eliminate multiple guards in rules
\item Transform \pr{where} declarations into \pr{let} declarations
\item Eliminate local patterns and functions
\end{enumerate}
These steps are described in the following.
For the following we assume that all name conflicts have been resolved,
%
For the following, we assume that all name conflicts have been resolved,
i.e., the names of functions and argument variables defined
in the different declarations are pairwise different.
Furthermore, we assume that all $\lambda$-abstractions have
been eliminated by providing a new name (cf.\ Section~\ref{app-higher-order}),
i.e., each $\lambda$-abstraction \pr{(\ttbs$x_1\ldots x_n$->$e$)}
is replaced by the expression \pr{($f~y_1\ldots y_m$)}
together with the new top-level definition
\startprog
$f~x_1\ldots{}x_n~y_1\ldots{}y_m$ = $e$
\stopprog
where $f$ is a new function name and $y_1\ldots y_m$ are the free variables
occurring in $e$ and different from $x_1\ldots x_n$.
Then we perform the following steps
for each rule ``\pr{$l$\,|\,$c$\,=\,$r$~where~$decls$}'':
\begin{description}
\item[Eliminate sections and lambda abstractions:]~\\
Each \emph{left section}\index{section}\index{section!left}\index{left section}
\pr{($expr$ $op$)} is transformed into
the partial application \pr{(($op$) $expr$)}.
Each \emph{right section}\index{section}\index{section!right}\index{right section}
\pr{($op$ $expr$)} is transformed into
the lambda abstraction \pr{(\ttbs{}$x$->($op$) $x$ $expr$)}
where $x$ is a new variable.
All $\lambda$-abstractions\index{lambda-abstraction@$\lambda$-abstraction}
are eliminated by providing a new name
(cf.\ Section~\ref{app-higher-order}), i.e.,
each $\lambda$-abstraction \pr{(\ttbs$x_1\ldots x_n$->$e$)}
is replaced by the expression \pr{(let $f~x_1\ldots x_n$ = $e$ in $f$)}
where $f$ is a new function name.
This transformation must be recursively applied to all
$\lambda$-abstractions occurring in $e$.
\item[Eliminate multiple guards:]~\\
This is done according the meaning described in Section~\ref{sec-bool-guards}.
A rule of the form
......@@ -4234,13 +4245,20 @@ but provides for a unified treatment of the elimination
of local pattern and function declarations in \pr{let} and \pr{where}.
\item[Eliminate local patterns and functions:]~\\
All local pattern and function declarations in a rule
``\pr{$l$\,\,=\,\,let\,\,$decls$\,\,in\,\,$r$}'' are stepwise eliminated
by applying the following transformations as long as possible:\footnote{%
If the right-hand side $r$ has not a \pr{let} declaration with local
patterns or functions at the top,
then these transformations are applied to an outermost \pr{let}
declaration in $r$.}
All local pattern\index{local pattern}\index{pattern!local}
and function declarations\index{local declaration}\index{declaration!local}
in a rule ``\pr{$l$\,\,=\,$r$}'' are eliminated as follows.
If $r$ is not a \pr{let} declaration but contains one,
we select an outermost \pr{let} declaration in $r$,
i.e., $r = r[\pr{let\,\,$decls$\,\,in\,\,$e$}]_p$, where $p$ is an outermost
position with this property but not the root,
and move it to the root by replacing ``\pr{$l$\,\,=\,$r$}''
by ``\pr{$l$\,\,=\,\,let\,\,$decls$\,\,in\,\,$r[e]_p$}''.
For a rule of the form
``\pr{$l$\,\,=\,\,let\,\,$decls$\,\,in\,\,$r$}'',
we apply the following transformations as long as possible:
\begin{description}
\item[Eliminate patterns:]~\\
Select a local pattern declaration which contains only
......@@ -4269,8 +4287,10 @@ until all local pattern declarations are eliminated.
\item[Complete local function definitions:]~\\
If a locally declared function $f$ refers in its definition
to a variable $v$ not contained in its argument patterns,
then add the argument $v$ to all occurrences of $f$ (i.e., left-hand
sides and calls). Repeat this step until all locally defined
then add $v$ as an additional first\footnote{The new arguments must come
first because of possible partial applications of this function.}
argument to all occurrences of $f$
(i.e., left-hand sides and calls). Repeat this step until all locally defined
functions are completed. Note that this completion step must also
be applied to free variables introduced in the same \pr{let}
expression, i.e., the rule
......@@ -4282,8 +4302,8 @@ f x = let y free
is completed to
\startprog
f x = let y free
g z y = c y z
in g 0 y
g y z = c y z
in g y 0
\stopprog
\item[Globalize local function definitions:]~\\
......@@ -4293,8 +4313,8 @@ patterns, delete the locally declared functions and
define them at the top-level. For instance, the previous
rule is transformed into the definitions
\startprog
g z y = c y z
f x = let y free in g 0 y
g y z = c y z
f x = let y free in g y 0
\stopprog
Note that the entire transformation process must be applied again
to the new top-level declarations since they may also contain
......@@ -4302,8 +4322,24 @@ local declarations.
\end{description}
\end{description}
After applying these transformation steps to all rules in the program,
we obtain a program where the local declarations contains only
free variables.
we obtain a program without sections and $\lambda$-abstractions
where all local declarations contain only free variables.
Note that partial applications are not eliminated since
they can be treated as shown in Section~\ref{app-higher-order}.
The final program might not be a valid Curry program due to the
transformation of \pr{where} declarations into \pr{let} declarations.
In order to obtain a valid Curry program, we can perform the
following final transformations:
\begin{center}
\begin{tabular}{l@{\hspace{4ex}}l@{\hspace{4ex}}l@{\hspace{4ex}}l}
Transform & \pr{$l$ = let $decls$ in ($c$|$r$)} & into & \pr{$l$ | $c$ = $r$ where $decls$} \\
and & \pr{$l$ = let $decls$ in $r$} & into & \pr{$l$ = $r$ where $decls$}
\end{tabular}
\end{center}
The latter transformation is only necessary if $r$ is not of type
\pr{Constraint}.
\newpage
\addcontentsline{toc}{section}{Bibliography}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment