f878ecf89711dfacc5c1467650bccdbd4368a7f4
[msc-thesis1617.git] / pres.mtask.tex
1 \subsection{EDSLs}
2 \begin{frame}
3 \frametitle{Embedded Domain Specific Language}
4 \framesubtitle{What is are EDSL}
5 \begin{itemize}
6 \item DSL:\ language for a specific domain
7 \item E.g., PostScript, VimScript, HTML, \ldots
8 \pause{}
9 \item EDSL:\ Embedded DSL
10 \item Language in a language
11 \item Use the properties of the host
12 \item E.g., Ivory, \ldots\pause{} and iTasks
13 \end{itemize}
14 \end{frame}
15
16 \begin{frame}[fragile]
17 \frametitle{Deep embedding}
18 \begin{columns}[t]
19 \column{.49\textwidth}
20 \begin{block}{What is deep embedding}
21 \begin{itemize}
22 \item The EDSL as an ADT
23 \item A view is a function transforming the ADT
24 \end{itemize}
25 \end{block}
26 \column{.49\textwidth}
27 \pause{}
28 \begin{lstlisting}
29 :: DSL = LitI Int | LitB Bool
30 | Var String | Plus DSL DSL
31 | Minus DSL DSL | And DSL DSL
32 | Eq DSL
33
34 eval :: DSL Env -> Env
35 pprint :: DSL -> String
36 \end{lstlisting}
37 \end{columns}
38 \pause{}
39 \begin{block}{Properties}
40 \begin{itemize}
41 \item Easy to add views
42 \item Hard to extend
43 \item Not type safe
44 \pause\item GADT
45 \end{itemize}
46 \end{block}
47 \end{frame}
48
49 \begin{frame}[fragile]
50 \frametitle{Shallow embedding}
51 \begin{columns}[t]
52 \column{.49\textwidth}
53 \begin{block}{What is shallow embedding}
54 \begin{itemize}
55 \item The EDSL as a function
56 \item The view is embedded in the function
57 \end{itemize}
58 \end{block}
59 \pause{}
60 \column{.49\textwidth}
61 \begin{lstlisting}
62 :: Env = ...
63 :: DSL a = DSL (Env -> a)
64
65 Lit :: a -> DSL a
66 Lit x = \e -> x
67
68 Var :: String -> DSL Int
69 Var i = \e -> retrEnv e i
70
71 Plus :: (DSL Int) (DSL Int) -> DSL Int
72 Plus x y = \e -> x e + y e
73 \end{lstlisting}
74 \end{columns}
75 \pause{}
76 \begin{block}{Properties}
77 \begin{itemize}
78 \item Difficult to add views
79 \item Easy to extend
80 \item Type safe
81 \end{itemize}
82 \end{block}
83 \end{frame}
84
85 \begin{frame}[fragile]
86 \frametitle{Class based shallow embedding}
87 \begin{columns}[t]
88 \column{.49\textwidth}
89 \onslide<1->{
90 \begin{block}{The best of both worlds}
91 \begin{itemize}
92 \item The EDSL is a collection of classes
93 \item Views are types implementing a subset
94 \end{itemize}
95 \end{block}
96 }
97 \onslide<3->{
98 \begin{block}{Properties}
99 \begin{itemize}
100 \item Extendable
101 \item Type safe
102 \item Easy to add views
103 \end{itemize}
104 \end{block}
105 }
106 \column{.49\textwidth}
107 \begin{onlyenv}<2->
108 \begin{lstlisting}
109 :: Env = ...
110 :: Evaluator a = Evaluator (Env -> a)
111 :: PrettyPrinter a = PP String
112
113 class intArith where
114 lit :: t -> v t | toString t
115 add :: (v t) (v t) -> (v t) | + t
116 minus :: (v t) (v t) -> (v t) | - t
117
118 class boolArith where ...
119
120 instance intArith Evaluator where
121 lit x = Evaluator \e->x
122 add x y = Evaluator ...
123 ...
124
125 instance intArith PrettyPrinter where
126 lit x = PP $ toString x
127 add x y = PP $ x +++ "+" +++ y
128 ...
129 \end{lstlisting}
130 \end{onlyenv}
131 \end{columns}
132 \end{frame}
133
134 \subsection{mTask}
135 \begin{frame}
136 \frametitle{mTask}
137 \pause{}
138 \begin{block}{What is mTask}
139 \begin{itemize}
140 \item EDSL
141 \item Arduino C++ generation, iTasks simulation
142 \end{itemize}
143 \end{block}
144
145 \begin{block}{Considerations}
146 \begin{itemize}
147 \item Type safe
148 \item Embedded in Clean
149 \item Extendable
150 \item \ldots\pause{} but\ldots
151 \item No interaction
152 \item Compilation requires reprogramming
153 \end{itemize}
154 \end{block}
155 \end{frame}