repositories
/
msc-thesis1617.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sweeeeep
[msc-thesis1617.git]
/
methods.dsl.tex
diff --git
a/methods.dsl.tex
b/methods.dsl.tex
index
1a153b1
..
8304262
100644
(file)
--- a/
methods.dsl.tex
+++ b/
methods.dsl.tex
@@
-23,19
+23,20
@@
Listing~\ref{lst:exdeep}.
| And DSL DSL
| Eq DSL
\end{lstlisting}
| And DSL DSL
| Eq DSL
\end{lstlisting}
+
Deep embedding has the advantage that it is very simple to build and the 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
Deep embedding has the advantage that it is very simple to build and the 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
a
boolean to an integer.
+such as \CI{Plus (LitI 4) (LitB True)} that adds a boolean to an integer.
Evermore so, extending the \gls{ADT} is easy and convenient but extending the
views accordingly is tedious and has to be done individually for all views.
The first downside of this type of \gls{EDSL} can be overcome by using
Evermore so, extending the \gls{ADT} is easy and convenient but extending the
views accordingly is tedious and has to be done individually for all views.
The first downside of this type of \gls{EDSL} can be overcome by using
-\glspl{GADT}\cite{cheney_first-class_2003}. Listing~\ref{lst:exdeepgadt} shows
+\glspl{GADT}
~
\cite{cheney_first-class_2003}. Listing~\ref{lst:exdeepgadt} shows
the same language, but type-safe with a \gls{GADT}. \glspl{GADT} are not
supported in the current version of \gls{Clean} and therefore the syntax is
hypothetical. However, it has been shown that \glspl{GADT} can be simulated
the same language, but type-safe with a \gls{GADT}. \glspl{GADT} are not
supported in the current version of \gls{Clean} and therefore the syntax is
hypothetical. However, it has been shown that \glspl{GADT} can be simulated
-using bimaps or projection pairs\cite{cheney_lightweight_2002}. Unfortunately
+using bimaps or projection pairs
~
\cite{cheney_lightweight_2002}. Unfortunately
the lack of extendability remains a problem. If a language construct is added,
no compile time guarantee is given that all views support it.
the lack of extendability remains a problem. If a language construct is added,
no compile time guarantee is given that all views support it.
@@
-79,9
+80,9
@@
Eq x y = \e -> x e + y e
The advantage of shallowly embedding a language in a host language is its
extendability. It is very easy to add functionality and compile time checks
The advantage of shallowly embedding a language in a host language is its
extendability. It is very easy to add functionality and compile time checks
-of the host language guarantee whether
the functionality is available when used.
-Moreover, the language is type safe as it is directly typed in the host
-language.
+of the host language guarantee whether
or not the functionality is available
+when used. Moreover, the language is type safe as it is directly typed in the
+
host
language.
The downside of this method is extending the language with views. It is nearly
impossible to add views to a shallowly embedded language. The only way of
The downside of this method is extending the language with views. It is nearly
impossible to add views to a shallowly embedded language. The only way of
@@
-91,9
+92,9
@@
implement all views rendering it slow for multiple views and complex to
implement.
\section{Class based shallow embedding}
implement.
\section{Class based shallow embedding}
-The third type of embedding is called class
based shallow embedding and has the
-advantages of both shallow and deep embedding. In class
based shallow embedding
-the language constructs are defined as type classes. Th
e same
language is shown
+The third type of embedding is called class
-
based shallow embedding and has the
+advantages of both shallow and deep embedding. In class
-
based shallow embedding
+the language constructs are defined as type classes. Th
is
language is shown
with the new method in Listing~\ref{lst:exclassshallow}.
This type of embedding inherits the easiness of adding views from shallow
with the new method in Listing~\ref{lst:exclassshallow}.
This type of embedding inherits the easiness of adding views from shallow
@@
-101,14
+102,17
@@
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.
type classes as shown in the aforementioned Listing where an evaluator and a
pretty printer are implemented.
-Just as with \glspl{GADT}
in deep embedding type safety is guaranteed
. Type
+Just as with \glspl{GADT}
, type safety is guaranteed in deep embedding
. Type
constraints are enforced through phantom types. One can add as many phantom
constraints are enforced through phantom types. One can add as many phantom
-type as necessary. Lastly, extensions can be added easily, just as in
+type
s
as necessary. Lastly, extensions can be added easily, just as in
shallow embedding. When an extension is made in an existing class, all views
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.
shallow embedding. When an extension is made in an existing class, all views
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.
+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
@@
-132,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 a & boolArith a
+ e0 = eq (lit 42) (lit 21 +. lit 21)
+
+ print (PP p) = p
+ eval (Evaluator e) env = e env
\end{lstlisting}
\end{lstlisting}