add part about deep embedding
[msc-thesis1617.git] / methods.dsl.tex
index 50a5138..639eec4 100644 (file)
@@ -1,4 +1,56 @@
 \section{\acrlong{EDSL}s}
+There are several techniques available for creating \glspl{EDSL}. Each of
+them have their own advantages and disadvantages such as extendability,
+typedness and view support. In the following subsections each of the main
+techniques are briefly explained.
+
+\subsection{Deep embedding}
+A deep \gls{EDSL} means that the language is represented as an \gls{ADT}. Views
+are functions that transform something to the datatype or the other way around.
+As an example we have the simple arithmetic \gls{EDSL} shown in
+Listing~\ref{lst:exdeep}. Deep embedding has the advantage that it is very
+simple to build and the views are easy to make and add. However, there are also
+a few downsides.
+
+\begin{lstlisting}[language=Clean,label={lst:exdeep},caption={A minimal deep
+\gls{EDSL}}]
+:: DSL
+       = LitI Int
+       | LitB Bool
+       | Var String
+       | Plus DSL DSL
+       | Minus DSL DSL
+       | And DSL DSL
+       | Eq DSL
+\end{lstlisting}
+
+The expressions created with this language are not type-safe. In the given
+language it is possible an expression such as \CI{Plus (LitI 4) (LitB True)}
+which to add 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 the type of \gls{EDSL} can be overcome by using
+\glspl{GADT}. Listing~\ref{lst:exdeepgadt} shows the same language, but
+type-safe with a \gls{GADT}\footnote{Note that \glspl{GADT} are not supported
+in \gls{Clean}. They can be simulated using bimaps}\todo{cite}. Unfortunately
+the lack of extendability stays a problem.
+
+\begin{lstlisting}[language=Clean,label={lst:exdeep},%
+       caption={A minimal deep \gls{EDSL}}]
+:: DSL a
+       = LitI Int                     -> DSL Int
+       | LitB Bool                    -> DSL Bool
+       | Var String                   -> DSL Int
+       | Plus   (DSL Int) (DSL Int)   -> DSL Int
+       | Minus  (DSL Int) (DSL Int)   -> DSL Int
+       | And    (DSL Bool) (DSL Bool) -> DSL Bool
+       | E.e: Eq (DSL e) (DSL e)       -> DSL Bool   & == e
+\end{lstlisting}
+
+\subsection{Shallow embedding}
+
+\subsection{Class based shallow embedding}
 \todo{while iTasks is also a DSL\ldots}
 \glspl{mTask} are expressed in a class based shallowly embedded \gls{EDSL}.
 There are two main types of \glspl{EDSL}.