\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}
+ \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}
+ \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}
}
\column{.49\textwidth}
\begin{onlyenv}<2->
- \begin{lstlisting}
+ \begin{lstlisting}[language=Clean]
:: Env = ...
:: 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
\begin{block}{What is mTask}
\begin{itemize}
\item Created by Pieter Koopman and Rinus Plasmeijer
- \item EDSL
+ \item EDSL for imperative programs
\item Arduino C++ generation, iTasks simulation
\end{itemize}
\end{block}
\begin{frame}[fragile]
\frametitle{Expressions}
\begin{block}{mTask}
- \begin{itemize}[<+->]
- \item Of the form \CI{v t p}
- \item \CI{p} is hierarchical
- \end{itemize}
+ Of the form \CI{v t p}
\end{block}
\pause{}
- \begin{lstlisting}
+ \begin{lstlisting}[language=Clean]
class arith v where
lit :: t -> v t Expr
(+.) infixl 6 :: (v t p) (v t q) -> v t Expr | +, zero t & isExpr p & isExpr q
\begin{frame}[fragile]
\frametitle{Control flow}
- \begin{lstlisting}
+ \begin{lstlisting}[language=Clean]
class IF v where
IF :: (v Bool p) (v t q) (v s r) -> v () Stmt | ...
(?) infix 1 :: (v Bool p) (v t q) -> v () Stmt | ...
\begin{frame}[fragile]
\frametitle{Assignment and Input/Output}
- \begin{lstlisting}
+ \begin{lstlisting}[language=Clean]
:: DigitalPin = D0 | D1 | D2 ...
:: AnalogPin = A0 | A1 | A2 ...
\begin{frame}[fragile]
\frametitle{Shared Data Sources and Assignment}
- \begin{lstlisting}
+ \begin{lstlisting}[language=Clean]
:: In a b = In infix 0 a b
:: Main a = {main :: a}
\end{lstlisting}
\end{frame}
+
\begin{frame}[fragile]
- \frametitle{Examples}
- \begin{lstlisting}
+ \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 ==. lit True)
+ IF x
(ledOn LED1)
(ledOff LED2) :.
blink (lit 1000) (Not x))
In {main=blink (lit 1000) True}
thermostat :: Main (View () Stmt)
-thermostat = {main = IF (analogRead A0 >. lit 50)
- ( digitalWrite D0 (lit True) )
- ( digitalWrite D0 (lit False) )
- }
+thermostat = {main = digitalWrite (dIO D0) (analogRead A0 >. lit 50)
thermostat2 :: Main (View () Stmt)
-thermostat2 = let a0 = aIO A0
- d0 = dIO D0
- in {main = IF (a0 >. lit 50)
- (d0 =. lit True)
- (d0 =. lit False)
- }
+thermostat = {main = (dIO D0) =. (analogRead A0 >. lit 50)
\end{lstlisting}
\end{frame}