\subsection{EDSLs}
\begin{frame}
\frametitle{Embedded Domain Specific Language}
- \framesubtitle{What is are EDSL}
+ \framesubtitle{What are EDSLs}
\begin{itemize}
\item DSL:\ language for a specific domain
\item E.g., PostScript, VimScript, HTML, \ldots
\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}
+ \onslide<1->{
+ \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}
+ }
+ \onslide<3->{
+ \begin{block}{Properties}
+ \begin{itemize}
+ \item Easy to add views
+ \item Hard to extend
+ \item Not type safe
+ \onslide<4->{
+ \item GADT
+ }
+ \end{itemize}
+ \end{block}
+ }
\column{.49\textwidth}
- \pause{}
- \begin{lstlisting}[language=Clean]
+ \begin{onlyenv}<2->
+ \begin{lstlisting}[language=Clean]
:: DSL = LitI Int | LitB Bool
| Var String | Plus DSL DSL
| Minus DSL DSL | And DSL DSL
eval :: DSL Env -> Env
pprint :: DSL -> String
- \end{lstlisting}
+ \end{lstlisting}
+ \end{onlyenv}
\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{}
+ \onslide<1->{
+ \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}
+ }
+
+ \onslide<2->{
+ \begin{block}{Properties}
+ \begin{itemize}
+ \item Difficult to add views
+ \item Easy to extend
+ \item Type safe
+ \end{itemize}
+ \end{block}
+ }
\column{.49\textwidth}
- \begin{lstlisting}[language=Clean]
+ \begin{onlyenv}<2->
+ \begin{lstlisting}[language=Clean]
:: Env = ...
:: DSL a = DSL (Env -> a)
Plus :: (DSL Int) (DSL Int) -> DSL Int
Plus x y = \e -> x e + y e
- \end{lstlisting}
+ \end{lstlisting}
+ \end{onlyenv}
\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}[fragile]
\item Extendable
\item Type safe
\item Easy to add views
+ \item Phantom types for extra constraints
\end{itemize}
\end{block}
}
:: Evaluator a = Evaluator (Env -> a)
:: PrettyPrinter a = PP String
-class intArith where
+class intArith v 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 ...
+class boolArith v where ...
instance intArith Evaluator where
lit x = Evaluator \e->x
\end{lstlisting}
\end{frame}
+
\begin{frame}[fragile]
- \frametitle{Examples}
+ \frametitle{Tasks and Examples}
+ \begin{lstlisting}[language=Clean]
+class mtask v a where
+ task :: (((v delay r) a -> v MTask Expr) -> In (a->v u p) (Main (v t q)))
+ -> Main (v t q) | ...
+ \end{lstlisting}
+ \pause{}
\begin{lstlisting}[language=Clean]
blink = task \blink=(\x.
- IF x)
+ IF x
(ledOn LED1)
(ledOff LED2) :.
blink (lit 1000) (Not x))