3 \frametitle{Embedded Domain Specific Language
}
4 \framesubtitle{What is are EDSL
}
6 \item DSL:\ language for a specific domain
7 \item E.g., PostScript, VimScript, HTML,
\ldots
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
14 \item Different embedding techniques
18 \begin{frame
}[fragile
]
19 \frametitle{Deep embedding
}
21 \column{.49\textwidth}
22 \begin{block
}{What is deep embedding
}
24 \item The EDSL as an ADT
25 \item A view is a function transforming the ADT
28 \column{.49\textwidth}
31 :: DSL = LitI Int | LitB Bool
32 | Var String | Plus DSL DSL
33 | Minus DSL DSL | And DSL DSL
36 eval :: DSL Env -> Env
37 pprint :: DSL -> String
41 \begin{block
}{Properties
}
43 \item Easy to add views
51 \begin{frame
}[fragile
]
52 \frametitle{Shallow embedding
}
54 \column{.49\textwidth}
55 \begin{block
}{What is shallow embedding
}
57 \item The EDSL as a function
58 \item The view is embedded in the function
62 \column{.49\textwidth}
65 :: DSL a = DSL (Env -> a)
70 Var :: String -> DSL Int
71 Var i =
\e -> retrEnv e i
73 Plus :: (DSL Int) (DSL Int) -> DSL Int
74 Plus x y =
\e -> x e + y e
78 \begin{block
}{Properties
}
80 \item Difficult to add views
87 \begin{frame
}[fragile
]
88 \frametitle{Class based shallow embedding
}
90 \column{.49\textwidth}
92 \begin{block
}{The best of both worlds
}
94 \item The EDSL is a collection of classes
95 \item Views are types implementing a subset
100 \begin{block
}{Properties
}
104 \item Easy to add views
108 \column{.49\textwidth}
112 :: Evaluator a = Evaluator (Env -> a)
113 :: PrettyPrinter a = PP String
116 lit :: t -> v t | toString t
117 add :: (v t) (v t) -> (v t) | + t
118 minus :: (v t) (v t) -> (v t) | - t
120 class boolArith where ...
122 instance intArith Evaluator where
123 lit x = Evaluator
\e->x
124 add x y = Evaluator ...
127 instance intArith PrettyPrinter where
128 lit x = PP $ toString x
129 add x y = PP $ x +++ "+" +++ y
140 \begin{block
}{What is mTask
}
142 \item Created by Pieter Koopman and Rinus Plasmeijer
144 \item Arduino C++ generation, iTasks simulation
148 \begin{block
}{Considerations
}
151 \item Embedded in Clean
157 \begin{frame
}[fragile
]
158 \frametitle{Expressions
}
160 \begin{itemize
}[<+->
]
161 \item Of the form
\CI{v t p
}
162 \item \CI{p
} is hierarchical
169 (+.) infixl
6 :: (v t p) (v t q) -> v t Expr | +, zero t & isExpr p & isExpr q
170 (-.) infixl
6 :: (v t p) (v t q) -> v t Expr | -, zero t & ...
172 class boolExpr v where
173 Not :: (v Bool p) -> v Bool Expr | ...
174 (&.) infixr
3 :: (v Bool p) (v Bool q) -> v Bool Expr | ...
176 (==.) infix
4 :: (v a p) (v a q) -> v Bool Expr | ...
180 \begin{frame
}[fragile
]
181 \frametitle{Control flow
}
184 IF :: (v Bool p) (v t q) (v s r) -> v () Stmt | ...
185 (?) infix
1 :: (v Bool p) (v t q) -> v () Stmt | ...
188 (:.) infixr
0 :: (v t p) (v u q) -> v u Stmt | ...
192 \begin{frame
}[fragile
]
193 \frametitle{Assignment and Input/Output
}
195 :: DigitalPin = D0 | D1 | D2 ...
196 :: AnalogPin = A0 | A1 | A2 ...
198 class dIO v where dIO :: DigitalPin -> v Bool Upd
199 class aIO v where aIO :: AnalogPin -> v Int Upd
201 class analogRead v where
202 analogRead :: AnalogPin -> v Int Expr
203 analogWrite :: AnalogPin (v Int p) -> v Int Expr
205 class digitalRead v where
206 digitalRead :: DigitalPin -> v Bin Expr
207 digitalWrite :: DigitalPin (v Bool p) -> v Int Expr
211 \begin{frame
}[fragile
]
212 \frametitle{Shared Data Sources and Assignment
}
214 :: In a b = In infix
0 a b
215 :: Main a =
{main :: a
}
218 sds :: ((v t Upd)->In t (Main (v c s))) -> (Main (v c s)) | ...
221 (=.) infixr
2 :: (v t Upd) (v t p) -> v t Expr | ...
225 \begin{frame
}[fragile
]
226 \frametitle{Examples
}
228 blink = task
\blink=(
\x.
232 blink (lit
1000) (Not x))
233 In
{main=blink (lit
1000) True
}
235 thermostat :: Main (View () Stmt)
236 thermostat =
{main = IF (analogRead A0 >. lit
50)
237 ( digitalWrite D0 (lit True) )
238 ( digitalWrite D0 (lit False) )
241 thermostat2 :: Main (View () Stmt)
242 thermostat2 = let a0 = aIO A0
244 in
{main = IF (a0 >. lit
50)