X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=dsl%2Fdsl_techniques.tex;h=22b9977febb5891791e4cc18b0d0ffe1b9fbbd9b;hb=0c4686b70dcb071a6537cdb52beb6bf4183334a1;hp=3e92c03c8bf300b9f9ca898b42ef870bf6a4a533;hpb=658c18356eecd7b43b27b5ee450db4d12a985834;p=phd-thesis.git diff --git a/dsl/dsl_techniques.tex b/dsl/dsl_techniques.tex index 3e92c03..22b9977 100644 --- a/dsl/dsl_techniques.tex +++ b/dsl/dsl_techniques.tex @@ -1,11 +1,9 @@ \documentclass[../thesis.tex]{subfiles} -\begin{document} -\ifSubfilesClassLoaded{ - \pagenumbering{arabic} -}{} +\include{subfilepreamble} -\chapter{\texorpdfstring{\Acrshort{DSL}}{DSL} embedding techniques}% +\begin{document} +\chapter{\texorpdfstring{\Glsxtrshort{DSL}}{DSL} embedding techniques}% \label{chp:dsl_embedding_techniques}% An \gls{EDSL} is a language embedded in a host language created for a specific domain\todo{citation needed?}. Properties such as referential transparency, minimal syntax, powerful type systems and rich data types make \gls{FP} languages excellent candidates for hosting \glspl{EDSL}. @@ -90,7 +88,7 @@ eval (Eq l r) = case (eval l, eval r) of (l, r) -> error ("Can't compare " ++ show l ++ " to " ++ show r) \end{lstHaskell} -\subsection{\texorpdfstring{\Acrlongpl{GADT}}{Generalised algebraic data types}} +\subsection{\texorpdfstring{\Glsxtrlongpl{GADT}}{Generalised algebraic data types}} Deep embedding has the advantage that it is easy to build and views are easy to add. On the downside, the expressions created with this language are not necessarily type-safe. In the given language it is possible to create an expression such as \haskellinline{LitI 4 `Plus` LitB True} that adds a boolean to an integer. @@ -99,7 +97,7 @@ Extending the \gls{ADT} is easy and convenient but extending the views according The first downside of this type of \gls{EDSL} can be overcome by using \glspl{GADT}~\citep{cheney_first-class_2003}. \Cref{lst:exdeepgadt} shows the same language, but type-safe with a \gls{GADT}. \glspl{GADT} are not supported in the current version of \gls{CLEAN} and therefore the syntax is hypothetical (See \todo{insert link to appendix}). -However, it has been shown that \glspl{GADT} can be simulated using bimaps or projection pairs~\citep[Sec.~2.2]{cheney_lightweight_2002}. +However, it has been shown that \glspl{GADT} can be simulated using bimaps or projection pairs~\citep[\citesection{2.2}]{cheney_lightweight_2002}. Unfortunately the lack of extendability remains a problem. If a language construct is added, no compile time guarantee can be given that all views support it. @@ -147,11 +145,11 @@ sub x y = \e->x e - y e \end{lstHaskell} Moreover, the language is type safe as it is directly typed in the host language, i.e.\ \haskellinline{lit True `plus` lit 4} is rejected. -Another advantage is the intimate link with the host language, allowing for a lot more linguistic reuse such as the support of implicit sharing~\cite{krishnamurthi_linguistic_2001}. +Another advantage is the intimate link with the host language, allowing for a lot more linguistic reuse such as the support of implicit sharing \citep{krishnamurthi_linguistic_2001}. The downside of this method is extending the language with views. It is nearly impossible to add views to a shallowly embedded language. -The only way of achieving this is by reimplementing all functions so that they run all backends at the same time or to create a single interpretation that produces a fold function~\citep{gibbons_folding_2014}. +The only way of achieving this is by reimplementing all functions so that they run all backends at the same time or to create a single interpretation that produces a fold function \citep{gibbons_folding_2014}. \subsection{Tagless-final embedding}\label{ssec:tagless} By lifting the functions representing the \gls{DSL} terms to type classes, interpretations can be added. @@ -168,7 +166,7 @@ class DSL v where An interpretation of this view is a data type that implements the type class. -\begin{lstHaskell}[label={lst:extagless},caption={A minimal tagless-final \gls{EDSL}.}] +\begin{lstHaskell}[label={lst:extaglessprint},caption={A pretty printer for the tagless-final \gls{EDSL}.}] data Print a = P {runPrint :: String} instance DSL Print where lit a = P (show a) @@ -189,7 +187,7 @@ instance Sub Print where Adding an interpretation means adding a data type and providing instances for the language constructs. -\begin{lstHaskell}[label={lst:extagless},caption={An evaluator interpretation of the minimal tagless-final \gls{EDSL}.}] +\begin{lstHaskell}[label={lst:extaglesseval},caption={An evaluator interpretation of the minimal tagless-final \gls{EDSL}.}] data Eval a = Eval {runEval :: Env -> a} instance DSL v where @@ -207,7 +205,7 @@ Both flavours have their strengths and weaknesses and both flavours can be impro \begin{table}[ht] \begin{threeparttable}[b] - \caption{Comparison of embedding techniques, adapted from \citet[Sec.~3.6]{sun_compositional_2022}}% + \caption{Comparison of embedding techniques, adapted from \citet[\citesection{3.6}]{sun_compositional_2022}}% \label{tbl:dsl_comparison} \begin{tabular}{lllllll} \toprule