updates
[phd-thesis.git] / intro / intro.tex
index fbce504..c0cbb9e 100644 (file)
@@ -6,38 +6,56 @@
 \chapter{Prelude}%
 \label{chp:introduction}
 \begin{chapterabstract}
-       This chapter introduces the contents of the thesis and a reading guide.
-       Furthermore, it provides background material on \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, and \glsxtrlong{TOP}; and a detailed overview of the contributions.
-       It also gives a brief introduction to two \gls{TOP} languages: \gls{ITASK} and \gls{MTASK}.
+       This chapter:
+       \begin{itemize}
+               \item introduces the topic and research ventures of this dissertation;
+               \item shows a reading guide;
+               \item provides background material on \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, \glsxtrlong{TOP}, and the \gls{TOP} languages \gls{ITASK} and \gls{MTASK} in particular;
+               \item and concludes with a detailed overview of the contributions.
+       \end{itemize}
 \end{chapterabstract}
 
 There are at least 13.4 billion devices connected to the internet at the time of writing\footnote{\url{https://transformainsights.com/research/tam/market}, accessed on: \formatdate{13}{10}{2022}}.
-These devices sense, act, or otherwise interact with people, other computers, and the world surrounding us.
-Notwithstanding the substantial variety among these devices, they have one thing in common: they are all require software to operate.
+Each and every one of those devices senses, acts, or otherwise interacts with people, other computers, and the environment surrounding us.
+Even though there is a substantial variety among these devices, they have one thing in common: they all computers to some degree and for this reason require software to operate.
 
 An increasing amount of these connected devices are so-called \emph{edge devices} that operate in the \gls{IOT}.
-Typically these edge devices are small microcontrollers containing sensors and actuators to interact with the physical world.
-Microcontrollers are integrated circuits containing a microprocessor designed for use in embedded applications.
-The edge devices come in many different types and they differ substantially from the other devices in the system.
-Consequently, programming \gls{IOT} systems is very complex and error prone.
-Hence, an \gls{IOT} programmer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels resulting in semantic friction.
-
-This thesis introduces research on the many aspects of orchestrating \gls{IOT} systems using \gls{TOP}.
-\Gls{TOP} is a innovative tierless programming paradigm for programming multi-tier interactive systems using a single declarative specification of the work that needs to be done.
-Using advanced compiler technologies, much of the internals and communication of multi-tier applications is automatically generated and the result of compilation is a ready-for-work application.
-Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive to be suitable for the average edge device.
-
-This is where \glspl{DSL} come into play.
-\Glspl{DSL} are languages created with a specific domain in mind.
-Consequently, domain knowledge does not have to be expressed in the language itself but they can be built-in features, thus drastically reducing the hardware requirements even with high levels of abstraction.
+Typically, these edge devices are powered by microcontrollers
+Microcontrollers contain integrated circuits accommodating a microprocessor designed for use in embedded applications.
+Typical microprocessors therefore are tiny in size; have little memory; contain a slow, but energy efficient processor; and allow for a lot of connectivity to connect peripherals such as sensors and actuators to interact with their surroundings.
+%
+%\begin{figure}[ht]
+%      \centering
+%      \includegraphics[width=.4\linewidth]{esp}
+%      \caption{A typical ESP32 microcontroller prototyping board.}%
+%      \label{fig:esp_prototype}
+%\end{figure}
+
+Edge devices come in numerous types, differing substantially from the other devices in the system.
+An \gls{IOT} programmer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels resulting in semantic friction.
+Programming and maintaining \gls{IOT} systems is therefore a very complex and an error-prone process.
+
+This thesis introduces research on taming these complex \gls{IOT} systems using \gls{TOP}.
+\Gls{TOP} is an innovative tierless programming paradigm for programming multi-tier interactive systems using a single declarative specification of the work that needs to be done.
+By utilising advanced compiler technologies, much of the internals, communication, and interoperation of the multi-tier applications is automatically generated.
+The result of this compilation is a ready-for-work application.
+Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive for a general purpose \gls{TOP} system to be suitable for the average edge device.
+
+This is where \glspl{DSL} are brought into play.
+\Glspl{DSL} are programming languages created with a specific domain in mind.
+Consequently, domain jargon does not have to be expressed in the language itself, but they can be built-in features.
+As a result, the hardware requirements can be drastically lower even with high levels of abstraction.
+
+Using \gls{MTASK}, a novel domain-specific \gls{TOP} \gls{DSL} fully integrated with \gls{ITASK}, all layers of the \gls{IOT} can be orchestrated from a single source.
 
 \section{Reading guide}
+The thesis is presented as a purely functional rhapsody.
 On Wikipedia, a musical rhapsody is defined as follows \citep{wikipedia_contributors_rhapsody_2022}:
 \begin{quote}\emph{%
        A \emph{rhapsody} in music is a one-movement work that is episodic yet integrated, free-flowing in structure, featuring a range of highly contrasted moods, colour, and tonality.}
 \end{quote}
-This thesis is structured as a pure functional rhapsody containing three episodes barded by the introduction and conclusion (\cref{chp:introduction,chp:conclusion}).
-\Cref{prt:dsl} is a paper-based---otherwise known as cumulative---episode providing insight in advanced \gls{DSL} embedding techniques.
+The three episodes are barded by the introduction and conclusion (\cref{chp:introduction,chp:conclusion}).
+\Cref{prt:dsl} is a paper-based---otherwise known as cumulative---episode providing insight in advanced \gls{DSL} embedding techniques for \glspl{FP}.
 The chapters are readable independently.
 \Cref{prt:top} is a monograph showing \gls{MTASK}, a \gls{TOP} \gls{DSL} for the \gls{IOT}.
 Hence, the chapters are best read in order.
@@ -46,10 +64,10 @@ The chapter is readable independently.
 
 The following sections provide background material on the \gls{IOT}, \glspl{DSL}, and \gls{TOP} after which a detailed overview of the contributions is presented.
 Text typeset as \texttt{teletype} represents source code.
-Standalone source code listings are used are marked with the programming language used.
-For the \gls{FP} language \gls{CLEAN}, a guide tailored to \gls{HASKELL} programmers is available as in \cref{chp:clean_for_haskell_programmers}.
+Standalone source code listings are used are marked by the programming language used.
+Specifically for the \gls{FP} language \gls{CLEAN}, a guide tailored to \gls{HASKELL} programmers is available in \cref{chp:clean_for_haskell_programmers}.
 
-\section{Internet of things}\label{sec:back_iot}
+\section{\texorpdfstring{\Glsxtrlong{IOT}}{Internet of things}}\label{sec:back_iot}
 The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world.
 While the term \gls{IOT} briefly gained interest around 1999 to describe the communication of \gls{RFID} devices \citep{ashton_internet_1999,ashton_that_2009}, it probably already popped up halfway the eighties in a speech by \citet{peter_t_lewis_speech_1985}:
 
@@ -80,12 +98,12 @@ A cloud server or local server provides this layer in a typical home automation
 
 The perception layer---also called edge layer---collects the data and interacts with the environment.
 It consists of edge devices such as microcontrollers equipped with various sensors and actuators.
-In home automation this layer consists of all the devices hosting the sensors and actuators such as a smart lightbulb, an actuator to open a door or a temperature and humidity sensor.
+In home automation this layer consists of all the devices hosting the sensors and actuators such as a smart light bulb, an actuator to open a door or a temperature and humidity sensor.
 
 All layers are connected using the network layer.
 In many applications this is implemented using conventional networking techniques such as WiFi or Ethernet.
 However, networks or layers on top of it---tailored to the needs of the specific interconnection between layers---have been increasingly popular.
-Examples of this are \gls{BLE}, LoRa, ZigBee, LTE-M, or \gls{MQTT} for connecting the perception layer to the application layer and techniques such as HTTP, AJAX, and WebSocket for connecting the presentation layer to the application layer.
+Examples of this are BLE, LoRa, ZigBee, LTE-M, or \gls{MQTT} for connecting the perception layer to the application layer and techniques such as HTTP, AJAX, and WebSocket for connecting the presentation layer to the application layer.
 
 Across the layers, the devices are a large heterogeneous collection of different platforms, protocols, paradigms, and programming languages often resulting in impedance problems or semantic friction between layers when programming \citep{ireland_classification_2009}.
 Even more so, perception layer itself often is a heterogeneous collections of microcontrollers in itself as well, each having their own peculiarities, language of choice, and hardware interfaces.
@@ -122,8 +140,8 @@ Examples of standalone \glspl{DSL} are regular expressions, make, yacc, XML, SQL
 
 The dichotomous approach is embedding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL} \citep{hudak_modular_1998}.
 By defining the language as constructs in the host language, much of the machinery is inherited and the cost of creating embedded languages is very low.
-There is more linguistic reuse~\cite{krishnamurthi_linguistic_2001}.
-There are however two sides to the this coin.
+There is more linguistic reuse \citep{krishnamurthi_linguistic_2001}.
+However, there are two sides to this coin.
 If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} may become clumsy.
 Furthermore, errors shown to the programmer may be larded with host language errors, making it difficult for a non-expert of the host language to work with the \gls{DSL}.
 Pure \gls{FP} languages are especially suitable for hosting embedded \glspl{DSL} because they have strong and versatile type systems, minimal but flexible syntax and offer referential transparency.
@@ -182,8 +200,8 @@ This approach to software development is called \gls{TOSD} \citep{wang_maintaini
                Furthermore, a task is observable which means it is possible to observe a---partial---result during execution and act upon it by for example starting new tasks.
                Examples of tasks are filling in a form, sending an email, reading a sensor or even doing a physical task.
        \item[\Glsxtrshortpl{SDS} (resource access):]
-               Tasks can communicate using task values but this imposes a problem in many collaboration patterns where tasks that are not necessarily related need to share data.
-               Tasks can also share data using \glspl{SDS}, an abstraction over any data.
+               Tasks can communicate using task values, some collaboration require tasks that are not necessarily related need to share data.
+               Hence, tasks can also share data using \glspl{SDS}, an abstraction over any data.
                An \gls{SDS} can represent typed data stored in a file, a chunk of memory, a database \etc.
                \Glspl{SDS} can also represent external impure data such as the time, random numbers or sensory data.
                Similar to tasks, transformation and combination of \glspl{SDS} is possible.
@@ -208,9 +226,9 @@ Only when the user entered a complete value in the web editor, then the continue
 Special combinators (e.g.\ \cleaninline{@>>} at \cref{lst:task_ui}) are available to tweak the \gls{UI} afterwards.
 
 \begin{figure}[ht]
-       \includegraphics[width=.32\linewidth]{person0}
-       \includegraphics[width=.32\linewidth]{person1}
-       \includegraphics[width=.32\linewidth]{person2}
+       \includegraphics[width=.325\linewidth]{person0g}
+       \includegraphics[width=.325\linewidth]{person1g}
+       \includegraphics[width=.325\linewidth]{person2g}
        \caption{The \gls{UI} for entering a person in \gls{ITASK}.}%
        \label{fig:enter_person}
 \end{figure}
@@ -228,34 +246,38 @@ enterPerson
 \end{lstClean}
 
 \subsection{\texorpdfstring{\Gls{MTASK}}{MTask}}
-This thesis uses \gls{ITASK} in conjunction with an innovative \gls{TOP} language designed for defining interactive systems for \gls{IOT} edge devices called \gls{MTASK} \citep{koopman_task-based_2018}.
+This thesis uses \gls{ITASK} in conjunction with \gls{MTASK}, an innovative \gls{TOP} language designed for defining interactive systems for \gls{IOT} edge devices \citep{koopman_task-based_2018}.
 It is written in \gls{CLEAN} as a multi-view \gls{EDSL} and hence there are multiple interpretations of the language of which the byte code compiler is the most relevant for this thesis.
 From the terms in the \gls{TOP} language, a very compact binary representation of the work that needs to be done is compiled.
 This specification is then sent to a device that runs the \gls{MTASK} \gls{RTS}, a domain-specific \gls{TOP} engine implemented as a feather-light domain-specific \gls{OS}.
 \Gls{MTASK} is seamlessly integrated with \gls{ITASK}, it allows the programmer to define all layers of an \gls{IOT} system from a single declarative specification.
 
-\todo[inline]{Is this example useful? Add more detailed explanation with line numbers?}
-\Cref{lst:intro_blink} shows an \gls{MTASK}\slash{}\gls{ITASK} application for an interactive application where the \gls{LED} on the microcontroller blinks every user-specified interval.
-Using a \glspl{SDS} defined in \gls{ITASK}, the blinking frequency of an \gls{LED} connected to \gls{GPIO} pin 13 can be changed on the fly.
+\todo[inline]{Is this example useful? I think it's too technical}
+\Cref{lst:intro_blink} shows an interactive \gls{MTASK}\slash{}\gls{ITASK} application for blinking \pgls{LED} on the microcontroller every user-specified interval.
+\Crefrange{lst:intro:itask_fro}{lst:intro:itask_to} show the \gls{ITASK} part.
+First a \gls{SDS} is defined to communicate the blinking interval, then the \gls{MTASK} is connected using \cleaninline{withDevice}.
+Once connected, the \cleaninline{intBlink} task is sent to the device (\cref{lst:intro_liftmtask}) and in parallel, the value of the interval \gls{SDS} can be updated using an editor (\cref{lst:intro_editor}).
+The \cleaninline{intBlink} task (\crefrange{lst:intro:mtask_fro}{lst:intro:mtask_to}) is the \gls{MTASK} part of the application that has its own tasks, \glspl{SDS}, and \gls{UOD}.
+This task first defines \gls{GPIO} pin 13 to be of the output type (\cref{lst:intro:declarePin}) followed by lifting the \gls{ITASK} \gls{SDS} to an \gls{MTASK} \gls{SDS} (\cref{lst:intro:liftsds}).
+The main expression of the program calls the \cleaninline{blink} function with the initial state.
+This function on \crefrange{lst:intro:blink_fro}{lst:intro:blink_to} first reads the interval \gls{SDS}, waits the specified delay, writes the state to the \gls{GPIO} pin and calls itself recursively using the inverse of the state.
 
 \begin{lstClean}[numbers=left,caption={\Gls{MTASK}\slash{}\gls{ITASK} interactive blinking.},label={lst:intro_blink}]
-interactiveBlink :: Task Int
+interactiveBlink :: Task Int[+\label{lst:intro:itask_fro}+]
 interactiveBlink =
-       withShared 500 \iInterval->
+       withShared 500 \iInterval->[+\label{lst:intro_withshared}+]
        withDevice {TCPSettings | host = ..., port = ...} \dev->
-                   liftmTask (intBlink iInterval) dev
-               -|| Hint "Interval (ms)" @>> updateSharedInformation [] iInterval
+                   liftmTask (intBlink iInterval) dev[+\label{lst:intro_liftmtask}+]
+               -|| Hint "Interval (ms)" @>> updateSharedInformation [] iInterval[+\label{lst:intro_editor}+][+\label{lst:intro:itask_to}+]
 
-intBlink :: Shared sds Int -> MTask v Int | mtask, liftsds v & RWShared sds
+intBlink :: Shared sds Int -> MTask v Int | mtask, liftsds v & RWShared sds[+\label{lst:intro:mtask_fro}+]
 intBlink iInterval =
-          declarePin D13 PMOutput \d13->
-          liftsds \mInterval=iInterval
-       In fun \blink=(\st->
-                    writeD d13 st
-               >>|. getSds mInterval
-               >>=. \i->delay i
-               >>|. blink (Not st))
-       In {main = blink true}
+          declarePin D13 PMOutput \d13->[+\label{lst:intro:declarePin}+]
+          liftsds \mInterval=iInterval[+\label{lst:intro:liftsds}+]
+       In fun \blink=(\st->[+\label{lst:intro:blink_fro}+]
+                    getSds mInterval >>=. \i->delay i
+               >>|. writeD d13 st >>|. blink (Not st))[+\label{lst:intro:blink_to}+]
+       In {main = blink true}[+\label{lst:intro:mtask_to}+]
 \end{lstClean}
 
 \subsection{Other \texorpdfstring{\glsxtrshort{TOP}}{TOP} languages}
@@ -296,7 +318,7 @@ It provides a gentle introduction to the \gls{MTASK} system elaborates on \gls{T
                
                This paper was an extension of my Master's thesis \citep{lubbers_task_2017}.
                It shows how a simple imperative variant of \gls{MTASK} was integrated with \gls{ITASK}.
-               While the language was a lot different than later versions, the integration mechanism is still used in \gls{MTASK} today.
+               While the language was a lot different from later versions, the integration mechanism is still used in \gls{MTASK} today.
 %              \paragraph{Contribution}
 %              The research in this paper and writing the paper was performed by me, though there were weekly meetings with Pieter Koopman and Rinus Plasmeijer in which we discussed and refined the ideas.
        \item \emph{Multitasking on Microcontrollers using Task Oriented Programming} \citep{lubbers_multitasking_2019}\footnote{%