+\begin{frame}[fragile]
+ \frametitle{Implementation}
+ \begin{itemize}
+ \item Writing instruction
+ \item Carrying state
+ \item Hand-crafted helpers
+ \end{itemize}
+ \begin{lstlisting}
+op2 :: (ByteCode a p1) (ByteCode a p2) BC -> ByteCode b Expr
+op2 (BC x) (BC y) bc = BC (x >>| y >>| tell [bc])
+
+tell2 :: [BC] -> (ByteCode a p)
+tell2 x = BC (tell x)
+
+instance arith ByteCode where
+ lit x = tell2 [BCPush (BCValue x)]
+ (+.) x y = op2 x y BCDiv
+ ...
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Control flow}
+ \begin{itemize}
+ \item Use labels
+ \item Label resolving
+ \pause{}
+ \item Thus no reuse
+ \end{itemize}
+ \pause{}
+ \begin{lstlisting}
+:: BC = ... | BCLab Int | ...
+
+freshlabel = get >>= \st=:{freshl}->put {st & freshl=freshl+1} >>| pure freshl
+
+instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
+...
+BCIfStmt (BC b) (BC t) (BC e) = BC (
+ freshlabel >>= \else->freshlabel >>= \endif->
+ b >>| tell [BCJmpF else] >>|
+ t >>| tell [BCJmp endif, BCLab else] >>|
+ e >>| tell [BCLab endif]
+ )
+ \end{lstlisting}
+\end{frame}
+