\subsection{EDSLs}
\begin{frame}
	\frametitle{Embedded Domain Specific Language}
	\framesubtitle{What are EDSLs}
	\begin{itemize}
		\item DSL:\ language for a specific domain
		\item E.g., PostScript, VimScript, HTML, \ldots
		\pause{}
		\item EDSL:\ Embedded DSL
		\item Language in a language
		\item Use the properties of the host
		\item E.g., Ivory, \ldots\pause{} and iTasks
		\pause{}
		\item Different embedding techniques
	\end{itemize}
\end{frame}

\begin{frame}[fragile]
	\frametitle{Deep embedding}
	\begin{columns}[t]
		\column{.49\textwidth}
		\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}
		\begin{onlyenv}<2->
			\begin{lstlisting}[language=Clean]
:: DSL = LitI  Int     | LitB  Bool
       | Var   String  | Plus  DSL DSL
       | Minus DSL DSL | And   DSL DSL
       | Eq    DSL

eval   :: DSL Env -> Env
pprint :: DSL -> String
			\end{lstlisting}
		\end{onlyenv}
	\end{columns}
\end{frame}

\begin{frame}[fragile]
	\frametitle{Shallow embedding}
	\begin{columns}[t]
		\column{.49\textwidth}
		\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{onlyenv}<2->
			\begin{lstlisting}[language=Clean]
:: Env   = ...
:: DSL a = DSL (Env -> a)

Lit :: a -> DSL a
Lit x = \e -> x

Var :: String -> DSL Int
Var i = \e -> retrEnv e i

Plus :: (DSL Int) (DSL Int) -> DSL Int
Plus x y = \e -> x e + y e
			\end{lstlisting}
		\end{onlyenv}
	\end{columns}
\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
					\item Phantom types for extra constraints
				\end{itemize}
			\end{block}
		}
		\column{.49\textwidth}
		\begin{onlyenv}<2->
			\begin{lstlisting}[language=Clean]
:: Env   = ...
:: Evaluator a = Evaluator (Env -> a)
:: PrettyPrinter a = PP String

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 v 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}
%\begin{frame}
%	\frametitle{mTask}
%	\pause{}
%	\begin{block}{What is mTask}
%		\begin{itemize}
%			\item Created by Pieter Koopman and Rinus Plasmeijer
%			\item EDSL for imperative programs
%			\item Arduino C++ generation, iTasks simulation
%		\end{itemize}
%	\end{block}
%
%	\begin{block}{Considerations}
%		\begin{itemize}
%			\item Type safe
%			\item Embedded in Clean
%			\item Extendable
%		\end{itemize}
%	\end{block}
%\end{frame}
%
%\begin{frame}[fragile]
%	\frametitle{Expressions}
%	\begin{block}{mTask}
%		Of the form \CI{v t p}
%	\end{block}
%	\pause{}
%	\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
%  (-.) infixl 6 :: (v t p) (v t q) -> v t Expr | -, zero t & ...
%  ...
%class boolExpr v where
%  Not           :: (v Bool p) -> v Bool Expr            | ...
%  (&.) infixr 3 :: (v Bool p) (v Bool q) -> v Bool Expr | ...
%  ...
%  (==.) infix 4 :: (v a p) (v a q) -> v Bool Expr       | ...
%	  \end{lstlisting}
%\end{frame}
%
%\begin{frame}[fragile]
%	\frametitle{Control flow}
%	\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 | ...
%
%class seq v where
%  (:.) infixr 0 :: (v t p) (v u q) -> v u Stmt | ...
%	\end{lstlisting}
%\end{frame}
%
%\begin{frame}[fragile]
%	\frametitle{Assignment and Input/Output}
%	\begin{lstlisting}[language=Clean]
%:: DigitalPin = D0 | D1 | D2 ...
%:: AnalogPin  = A0 | A1 | A2 ...
%
%class dIO v where dIO :: DigitalPin -> v Bool Upd
%class aIO v where aIO :: AnalogPin -> v Int Upd
%
%class analogRead v where
%  analogRead :: AnalogPin -> v Int Expr
%  analogWrite :: AnalogPin (v Int p) -> v Int Expr
%
%class digitalRead v where
%  digitalRead :: DigitalPin -> v Bin Expr
%  digitalWrite :: DigitalPin (v Bool p) -> v Int Expr
%  \end{lstlisting}
%\end{frame}
%
%\begin{frame}[fragile]
%	\frametitle{Shared Data Sources and Assignment}
%	\begin{lstlisting}[language=Clean]
%:: In a b = In infix 0 a b
%:: Main a = {main :: a}
%
%class sds v where
%  sds :: ((v t Upd)->In t (Main (v c s))) -> (Main (v c s)) | ...
%
%class assign v where
%  (=.) infixr 2 :: (v t Upd) (v t p) -> v t Expr | ...
%	\end{lstlisting}
%\end{frame}
%
%
%\begin{frame}[fragile]
%	\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
%               (ledOn LED1)
%               (ledOff LED2) :.
%            blink (lit 1000) (Not x))
%        In {main=blink (lit 1000) True}
%
%thermostat :: Main (View () Stmt)
%thermostat = {main = digitalWrite (dIO D0) (analogRead A0 >. lit 50)
%
%thermostat2 :: Main (View () Stmt)
%thermostat = {main = (dIO D0) =. (analogRead A0 >. lit 50)
%	\end{lstlisting}
%\end{frame}
