repositories
/
msc-thesis1617.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of git.martlubbers.net:msc-thesis1617
[msc-thesis1617.git]
/
methods.dsl.tex
diff --git
a/methods.dsl.tex
b/methods.dsl.tex
index
be8bf74
..
b7103ef
100644
(file)
--- a/
methods.dsl.tex
+++ b/
methods.dsl.tex
@@
-1,7
+1,7
@@
An \gls{EDSL} is a language embedded in a host language. \glspl{EDSL} can have
one or more backends or views. Commonly used views are pretty printing,
compiling, simulating, verifying and proving the program. There are several
An \gls{EDSL} is a language embedded in a host language. \glspl{EDSL} can have
one or more backends or views. Commonly used views are pretty printing,
compiling, simulating, verifying and proving the program. There are several
-techniques available for creating \glspl{EDSL}.
Each of them
have their own
+techniques available for creating \glspl{EDSL}.
They all
have their own
advantages and disadvantages in terms of extendability, typedness and view
support. In the following subsections each of the main techniques are briefly
explained.
advantages and disadvantages in terms of extendability, typedness and view
support. In the following subsections each of the main techniques are briefly
explained.
@@
-9,7
+9,7
@@
explained.
\section{Deep embedding}
A deep \gls{EDSL} is a language represented as an \gls{ADT}. Views are
functions that transform something to the datatype or the other way around. As
\section{Deep embedding}
A deep \gls{EDSL} is a language represented as an \gls{ADT}. Views are
functions that transform something to the datatype or the other way around. As
-an example
we hav
e the simple arithmetic \gls{EDSL} shown in
+an example
, tak
e the simple arithmetic \gls{EDSL} shown in
Listing~\ref{lst:exdeep}.
\begin{lstlisting}[label={lst:exdeep},%
Listing~\ref{lst:exdeep}.
\begin{lstlisting}[label={lst:exdeep},%
@@
-24,7
+24,7
@@
Listing~\ref{lst:exdeep}.
| Eq DSL
\end{lstlisting}
| Eq DSL
\end{lstlisting}
-Deep embedding has the advantage that it is
very simple to build and the
views
+Deep embedding has the advantage that it is
easy to build and
views
are easy to add. To the downside, the expressions created with this language
are not type-safe. In the given language it is possible to create an expression
such as \CI{Plus (LitI 4) (LitB True)} that adds a boolean to an integer.
are easy to add. To the downside, the expressions created with this language
are not type-safe. In the given language it is possible to create an expression
such as \CI{Plus (LitI 4) (LitB True)} that adds a boolean to an integer.
@@
-53,9
+53,9
@@
no compile time guarantee is given that all views support it.
\end{lstlisting}
\section{Shallow embedding}
\end{lstlisting}
\section{Shallow embedding}
-In a shallow
ly
\gls{EDSL} all language constructs are expressed as functions in
-the host language. An evaluator view for
our example language then looks
-
something like
the code shown in Listing~\ref{lst:exshallow}. Note that much of
+In a shallow \gls{EDSL} all language constructs are expressed as functions in
+the host language. An evaluator view for
the example language then can be
+
implemented as
the code shown in Listing~\ref{lst:exshallow}. Note that much of
the internals of the language can be hidden using monads.
\begin{lstlisting}[label={lst:exshallow},%
the internals of the language can be hidden using monads.
\begin{lstlisting}[label={lst:exshallow},%
@@
-97,7
+97,7
@@
advantages of both shallow and deep embedding. In class-based shallow embedding
the language constructs are defined as type classes. This language is shown
with the new method in Listing~\ref{lst:exclassshallow}.
the language constructs are defined as type classes. This language is shown
with the new method in Listing~\ref{lst:exclassshallow}.
-This type of embedding inherits the eas
iness
of adding views from shallow
+This type of embedding inherits the eas
e
of adding views from shallow
embedding. A view is just a different data type implementing one or more of the
type classes as shown in the aforementioned Listing where an evaluator and a
pretty printer are implemented.
embedding. A view is just a different data type implementing one or more of the
type classes as shown in the aforementioned Listing where an evaluator and a
pretty printer are implemented.
@@
-110,6
+110,9
@@
must be updated accordingly to prevent possible runtime errors. When an
extension is added in a new class, this problem does not arise and views can
choose to implement only parts of the collection of classes.
extension is added in a new class, this problem does not arise and views can
choose to implement only parts of the collection of classes.
+In contrast to deep embedding, it is very well possible to have multiple views
+applied on the same expression. This is also shown in the following listing.
+
\begin{lstlisting}[label={lst:exclassshallow},%
caption={A minimal class based shallow \gls{EDSL}}]
:: Env = ... // Some environment
\begin{lstlisting}[label={lst:exclassshallow},%
caption={A minimal class based shallow \gls{EDSL}}]
:: Env = ... // Some environment
@@
-133,4
+136,15
@@
instance intArith PrettyPrinter where
lit x = toString x
add x y = x +++ "+" +++ y
...
lit x = toString x
add x y = x +++ "+" +++ y
...
+
+...
+
+Start :: (PP String, Bool)
+Start = (print e0, eval e0)
+where
+ e0 :: a Bool | intArith, boolArith a
+ e0 = eq (lit 42) (lit 21 +. lit 21)
+
+ print (PP p) = p
+ eval (Evaluator e) env = e env
\end{lstlisting}
\end{lstlisting}