From: Mart Lubbers Date: Wed, 5 Jul 2017 15:14:20 +0000 (+0200) Subject: embedding examples X-Git-Tag: final~33 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=73ae126c560b79464769b58668f7543f7c4734c0;p=msc-thesis1617.git embedding examples --- diff --git a/pres.mtask.tex b/pres.mtask.tex index e0732f0..f878ecf 100644 --- a/pres.mtask.tex +++ b/pres.mtask.tex @@ -13,27 +13,122 @@ \end{itemize} \end{frame} -\begin{frame} - \frametitle{Embedded Domain Specific Language (2)} - \framesubtitle{Embedding techniques} - \begin{block}{Deep} - \end{block} +\begin{frame}[fragile] + \frametitle{Deep embedding} + \begin{columns}[t] + \column{.49\textwidth} + \begin{block}{What is deep embedding} + \begin{itemize} + \item The EDSL as an ADT + \item A view is a function transforming the ADT + \end{itemize} + \end{block} + \column{.49\textwidth} + \pause{} + \begin{lstlisting} +:: DSL = LitI Int | LitB Bool + | Var String | Plus DSL DSL + | Minus DSL DSL | And DSL DSL + | Eq DSL - \begin{block}{Shallow} +eval :: DSL Env -> Env +pprint :: DSL -> String + \end{lstlisting} + \end{columns} + \pause{} + \begin{block}{Properties} + \begin{itemize} + \item Easy to add views + \item Hard to extend + \item Not type safe + \pause\item GADT + \end{itemize} \end{block} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Shallow embedding} + \begin{columns}[t] + \column{.49\textwidth} + \begin{block}{What is shallow embedding} + \begin{itemize} + \item The EDSL as a function + \item The view is embedded in the function + \end{itemize} + \end{block} + \pause{} + \column{.49\textwidth} + \begin{lstlisting} +:: Env = ... +:: DSL a = DSL (Env -> a) + +Lit :: a -> DSL a +Lit x = \e -> x + +Var :: String -> DSL Int +Var i = \e -> retrEnv e i - \begin{block}{Class based shallow} +Plus :: (DSL Int) (DSL Int) -> DSL Int +Plus x y = \e -> x e + y e + \end{lstlisting} + \end{columns} + \pause{} + \begin{block}{Properties} + \begin{itemize} + \item Difficult to add views + \item Easy to extend + \item Type safe + \end{itemize} \end{block} \end{frame} -\begin{frame} - \frametitle{Embedded Domain Specific Language (2)} - \framesubtitle{Shallow Embedding} -\end{frame} +\begin{frame}[fragile] + \frametitle{Class based shallow embedding} + \begin{columns}[t] + \column{.49\textwidth} + \onslide<1->{ + \begin{block}{The best of both worlds} + \begin{itemize} + \item The EDSL is a collection of classes + \item Views are types implementing a subset + \end{itemize} + \end{block} + } + \onslide<3->{ + \begin{block}{Properties} + \begin{itemize} + \item Extendable + \item Type safe + \item Easy to add views + \end{itemize} + \end{block} + } + \column{.49\textwidth} + \begin{onlyenv}<2-> + \begin{lstlisting} +:: Env = ... +:: Evaluator a = Evaluator (Env -> a) +:: PrettyPrinter a = PP String -\begin{frame} - \frametitle{Embedded Domain Specific Language (3)} - \framesubtitle{Class Based Shallow Embedding} +class intArith where + lit :: t -> v t | toString t + add :: (v t) (v t) -> (v t) | + t + minus :: (v t) (v t) -> (v t) | - t + +class boolArith where ... + +instance intArith Evaluator where + lit x = Evaluator \e->x + add x y = Evaluator ... + ... + +instance intArith PrettyPrinter where + lit x = PP $ toString x + add x y = PP $ x +++ "+" +++ y + ... + \end{lstlisting} + \end{onlyenv} + \end{columns} \end{frame} \subsection{mTask} @@ -43,8 +138,7 @@ \begin{block}{What is mTask} \begin{itemize} \item EDSL - \item Generates C code - \item Arduino + \item Arduino C++ generation, iTasks simulation \end{itemize} \end{block} @@ -55,7 +149,7 @@ \item Extendable \item \ldots\pause{} but\ldots \item No interaction - \item Compilation + \item Compilation requires reprogramming \end{itemize} \end{block} \end{frame}