updates
[phd-thesis.git] / dsl / class_deep_embedding.tex
index 589c2f9..1cd911f 100644 (file)
@@ -126,7 +126,7 @@ One way to add semantics is to change all functions to execute both semantics at
 In our case this means changing the type of \haskelllhstexinline{Sem_s} to be \haskelllhstexinline{(Int, String)} so that all functions operate on a tuple containing the result of the evaluator and the printed representation at the same time. %chktex 36
 Alternatively, a single semantics can be defined that represents a fold over the language constructs~\citep{gibbons_folding_2014}, delaying the selection of semantics to the moment the fold is applied.
 
-\subsection{Tagless-final embedding}
+\subsection{Tagless-final embedding}\label{sec:tagless-final_embedding}
 Tagless-final embedding overcomes the limitations of standard shallow embedding.
 To upgrade to this embedding technique, the language constructs are changed from functions to type classes.
 For our language this results in the following type class definition.
@@ -687,7 +687,7 @@ This paper differs from those approaches in the sense that it does not require a
 There is no silver bullet to embedding \glspl{DSL}.
 \Citet{sun_compositional_2022} provided a thorough comparison of embedding techniques including more axes than just the two statet in the expression problem.
 
-\Cref{tbl:dsl_comparison} shows a variant of their comparison table.
+\Cref{tbl:dsl_comparison_brief} shows a variant of their comparison table.
 The first two rows describe the two axes of the original expression problem and the third row describes theadded axis of modular dependency handling as stated by \citeauthor{sun_compositional_2022}.
 The \emph{poly.} style of embedding---including tagless-final---falls short of this requirement.
 
@@ -809,7 +809,7 @@ This dictionary can then subsequently be used to apply the type class function o
 The \GHCmod{ScopedTypeVariables} extension is used to make sure the existentially quantified type variable for the extension is matched to the type of the dictionary.
 Furthermore, because the class constraint is not smaller than the instance head, \GHCmod{UndecidableInstances} should be enabled.
 
-\begin{lstHaskellLhstex}[caption={Evaluation instance for the main data type}]
+\begin{lstHaskellLhstex}
 class Eval v where
        eval :: v -> Int
 
@@ -822,15 +822,16 @@ instance Eval `In` s => Eval (Expr s) where
 Smart constructors need to be adapted as well, as can be seen from the smart constructor \haskelllhstexinline{subst}.
 Instead of a \haskelllhstexinline{GDict} class constraint, a \haskelllhstexinline{CreateRecord} class constraint needs to be added.
 
-\begin{lstHaskellLhstex}[caption={Substitution smart constructor}]
-subst :: (Typeable c, CreateRecord (Subt c) c) => Expr c -> Expr c -> Expr c
+\begin{lstHaskellLhstex}
+subst :: (Typeable c, CreateRecord (Subt c) c)
+       => Expr c -> Expr c -> Expr c
 subst l r = Ext createRecord (l `Subt` r)
 \end{lstHaskellLhstex}
 
 Finally, defining terms in the language can be done immediately if the interpretations are known.
 For example, if we want to print and/or optimise the term $~(~(42+(38-4)))$, we can define it as follows:
 
-\begin{lstHaskellLhstex}[caption={Substitution smart constructor}]
+\begin{lstHaskellLhstex}
 e0 :: Expr '[Print,Opt]
 e0 = neg (neg (Lit 42 `Add` (Lit 38 `subt` Lit 4)))
 \end{lstHaskellLhstex}
@@ -839,7 +840,7 @@ It is also possible to define terms in the \gls{DSL} as being overloaded in the
 This does require enumerating all the \haskelllhstexinline{CreateRecord} type classes for every extension in a similar fashion as was required for \haskelllhstexinline{GDict}.
 At the call site, the concrete list of constraints must be known.
 
-\begin{lstHaskellLhstex}[caption={Substitution smart constructor}]
+\begin{lstHaskellLhstex}
 e1 :: (Typeable c
        , CreateRecord (Neg c) c
        , CreateRecord (Subst c) c
@@ -869,8 +870,8 @@ e1 :: (Typeable c, UsingExt '[Neg, Subst]) => Expr c
 Giving an instance for \haskelllhstexinline{Interp} for \haskelllhstexinline{DataType} that uses the extensions \haskelllhstexinline{e_1, e2, ...} and depends on interpretations \haskelllhstexinline{i_1,i_2, ...} is done as follows:
 
 \begin{lstHaskellLhstex}
-instance ( UsingExt  '[e_1,e_2,...] s
-               , DependsOn '[i_1, i_2,...] s
+instance ( UsingExt  '[e_1, e_2, ...] s
+               , DependsOn '[i_1, i_2, ...] s
                ) => Interp (DataType s) where
        ...
 \end{lstHaskellLhstex}