\end{itemize}
\end{chapterabstract}
+This dissertation is about orchestrating \gls{IOT} systems harmlessly and efficiently.
+\todo{beter?}
There are at least 13.4 billion devices connected to the internet at the time of writing \citep{transforma_insights_current_2023}.
Each of these devices sense, act, or otherwise, interact with people, computers, and the environment.
Despite their immense diversity, they are all computers and they all require software to operate.
These miniature computers contain integrated circuits that accommodate a microprocessor designed for use in embedded applications.
As a consequence, microcontrollers are cheap; tiny; have little memory; and contain a slow, but energy-efficient processor.
-Unlike the conductor in an orchestra waving their baton to instruct the ensemble of instruments, in the universe of software there is room for little error.
-Moreover, in dynamic \gls{IOT} applications, there is not always a coordinating conductor.
-Edge devices---the instruments---come and go, perform their own pieces, or are sometimes instructed to perform a certain piece, they might even operate without a central authority.
+When coordinating an orchestra of edge devices, there is room for little error.
+Edge devices come and go, perform their own pieces, or are sometimes instructed to perform a certain piece, they might even operate without a central authority.
In a traditional setting, an \gls{IOT} engineer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels.
This results in semantic friction, which makes programming and maintaining \gls{IOT} systems a complex and error-prone process.
This dissertation describes the research carried out around orchestrating these complex \gls{IOT} systems using \gls{TOP}.
\Gls{TOP} is an innovative tierless programming paradigm for interactive multi-layered systems.
By utilising advanced compiler technologies, much of the internals, communication, and interoperation between the tiers or layers of the applications are automatically generated.
-From a single declarative specification of the work required, the compiler makes a ready-for-work application consisting of interconnected components for all tiers.
+The compiler makes an application controlling all interconnected components from a single declarative specification of the required work.
For example, the \gls{TOP} system \gls{ITASK} is used to program all layers of multi-user distributed web applications from a single source specification.
It is implemented in the general-purpose lazy functional programming language \gls{CLEAN}, and therefore requires relatively powerful hardware.
The inflated hardware requirements are no problem for regular computers but impractical for the average edge device.
-This is where \glspl{DSL} must be brought into play.
+This is where an additional \glspl{DSL} must play its part.
\Glspl{DSL} are programming languages tailored to a specific domain.
Consequently, jargon is not expressed in terms of the language itself, but are built-in language features.
Furthermore, the \gls{DSL} can eschew language or system features that are irrelevant for the domain.
Examples of this are BLE, LoRa, ZigBee, and LTE-M as a communication protocol for connecting the perception layer to the application layer using \gls{IOT} transport protocols such as \gls{MQTT}.
Protocols such as HTTP, AJAX, and WebSocket connecting the presentation layer to the application layer that are designed for the use in web applications.
+\todo[inline]{Hier enkele zinnen over maintainability}
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, the perception layer itself is often a heterogeneous collection of microcontrollers in itself, each having their own peculiarities, programming language of choice, and hardware interfaces.
As edge hardware needs to be cheap, small scale, and energy efficient, the microcontrollers used to power them do not have a lot of computational power, only a smidge of memory, and little communication bandwidth.
As a consequence, the flexibility is greatly reduced for dynamic systems in which tasks are created on the fly, executed on demand, require parallel execution, or have dynamic scheduling behaviour.
As program memory is mostly flash-based and only lasts a couple of thousands of writes before it wears out, it is not suitable for repeated reconfiguring and reprogramming.
-These problems can be mitigated by dynamically sending code to be interpreted to the microcontroller.
+Memory wear problems can be mitigated by dynamically sending code to be interpreted to the microcontroller.
With interpretation, a specialised interpreter is flashed in the program memory once it receives the program code to execute at run time.
Therefore, as the programs are not stored in the flash memory, it does not wear out.
It is challenging to create interpreters for small edge devices due to the severe hardware restrictions.
\subsection{The iTask system}
The concept of \gls{TOP} originated from the \gls{ITASK} framework, a declarative language and \gls{TOP} engine for defining interactive multi-user distributed web applications.
The \gls{ITASK} system is implemented as an \gls{EDSL} in the programming language \gls{CLEAN}\footnote{\Cref{chp:clean_for_haskell_programmers} contains a guide for \gls{CLEAN} tailored to \gls{HASKELL} programmers.} \citep{plasmeijer_itasks:_2007,plasmeijer_task-oriented_2012}.
-It has been under development for over fifteen years and has proven itself through use in industry for some time now as well.
+It is under development for over fifteen years and has proven itself through use in industry for some time now as well.
For example, it is the main language of VIIA, an advanced application for monitoring coasts \citep{top_software_viia_2023}.
From the structural properties of the data types and the current status of the work to be done, the entire \gls{UI} is automatically generated.
Browsers are powering \gls{ITASK}'s presentation layer.
Using \gls{ITASK}, complex collaborations of users and tasks can be described on a high level.
From the data type definitions (\cref{lst:todo_dt}), using generic programming (\cref{lst:todo_derive}), the \glspl{UI} for the data types are automatically generated.
-Then, using the parallel task combinator (\cleaninline{-\|\|}) the task for updating the to-dos (\cref{lst:todo_update}) and the task for viewing the length are combined (\cref{lst:todo_length}).
+Then, using the parallel task combinator (\cleaninline{-\|\|}) the task for updating the to-dos (\cref{lst:todo_update}) and the task for viewing the length are combined (\cref{lst:todo_length}, shown as \emph{Length: 2} in the bottom of the image).
This particular parallel combinator uses the result of the left-hand side task.
Both tasks operate on the to-do \gls{SDS} (\cref{lst:todo_sds}).
The task for updating the to-do list is an editor (\cref{lst:todo_editor}) combined using a step combinator (\crefrange{lst:todo_contfro}{lst:todo_contto}).
-The actions either change the value, sorting or clearing it, or terminate the task by returning the current value of the \gls{SDS}.
+The actions either change the value, sorting or clearing it, or terminate the task by returning the current value of the \gls{SDS}, visualised as three buttons on the bottom right of the \gls{UI}.
Special combinators (e.g.\ \cleaninline{@>>} at \cref{lst:todo_ui}) are used to tweak the \gls{UI} to display informative labels.
+\todo[inline]{Zou je hier niet zeggen dat dit iTask programma de Presentation en Application layer uit Figure 1.1 maakt door dezelfde code in de browser en op de server te runnen en alle netwerkdingen te genereren? Dat is hier wel niet erg nodig. Maar geeft je wel het opstapje om in 1.4.2.\ te zeggen dat de edge devices die wij willen gebruiken dat niet kunnen. Deze paragraaf kan ook in 1.4.2.}
\cleaninputlisting[float=,firstline=6,lastline=22,tabsize=3,numbers=left,caption={The code for a shared to-do list in \gls{ITASK}.},label={lst:todo}]{lst/sharedlist.icl}
Software on microcontrollers is usually composed of smaller basic tasks, are interactive, and share data with other components or the server.
The \gls{ITASK} system seems an obvious candidate for bringing \gls{TOP} to \gls{IOT} edge devices.
However, an \gls{ITASK} application contains many features that are not needed on \emph{edge devices} such as higher-order tasks, support for a distributed architecture, or a multi-user web server.
+\todo[inline]{Dat is op zich toch niet zo'n probleem. Een iTAsk server heeft ook geen GUI, maar wel alle iTask code om die te maken.
+Het feit dat dit niet hoeft op een edge device geeft je wel een van de handvatten om mTask in minder memory te runnen}
Furthermore, \gls{IOT} edge devices are in general not powerful enough to run or interpret \gls{CLEAN}\slash\gls{ABC} code, they just lack the processor speed and memory.
To bridge this gap, \gls{MTASK} is developed, a domain-specific \gls{TOP} system for \gls{IOT} edge devices that is integrated in \gls{ITASK} \citep{koopman_task-based_2018}.
The \gls{ITASK} language abstracts away from details such as user interfaces, data storage, client-side platforms, and persistent workflows.
Furthermore, \glspl{SDS} on the device can proxy \gls{ITASK} \glspl{SDS}.
Using \gls{MTASK}, the programmer can define all layers of an \gls{IOT} system as a single declarative specification.
The \gls{MTASK} language is written in \gls{CLEAN} as a multi-view \gls{EDSL} and hence there are multiple interpretations possible.
-The byte code compiler is the most relevant for this thesis.
+This thesis mostly discusses the byte code compiler.
From an \gls{MTASK} task constructed at run time, a compact binary representation of the work that needs to be done is compiled.
+And while the byte code for \gls{MTASK} is generated at run time, the type system of the host language \gls{CLEAN} prevents type errors in the generated code.
This byte code is then sent to a device that running the \gls{MTASK} \gls{RTS}.
This feather-light domain-specific \gls{OS} is written in portable \gls{C} with a minimal device specific interface and it executes the tasks using interpretation and rewriting.
The \gls{MTASK} device is connected using \cleaninline{withDevice} at \cref{lst:intro_withdevice}.
Once connected, the \cleaninline{intBlink} task is sent to the device (\cref{lst:intro_liftmtask}) and, in parallel, a web editor is shown that updates the value of the interval \gls{SDS} (\cref{lst:intro_editor,fig:intro_blink_int}).
To allow terminating of the task, the \gls{ITASK} task ends with a sequential operation that returns a constant value when the button is pressed, making the task stable.
-\todo{foto device+led?}
+\todo[inline]{foto device+led?}
+\todo[inline]{enterDevice nieuwe regel, globale func?}
\cleaninputlisting[float={!ht},firstline=10,lastline=18,numbers=left,caption={The \gls{ITASK} code for the interactive blinking application.},label={lst:intro_blink}]{lst/blink.icl}
\end{figure}
The \cleaninline{intBlink} task (\cref{lst:intro_blink_mtask}) is the \gls{MTASK} part of the application.
+It blinks \pgls{LED} on the edge device with the delay that is dynamically adjustable by the user via an \gls{ITASK} editor in the browser.
It 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}).
+This task first defines \gls{GPIO} pin 13 to be of the output type (\cref{lst:intro:declarePin}).
+Then the \gls{ITASK} \gls{SDS} is lifted to an \gls{MTASK} \gls{SDS} (\cref{lst:intro:liftsds}), enabling the machinery to keep the \gls{SDS} in sync both on the device and the server.
The main expression of the program calls the \cleaninline{blink} function with an 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 in order to run continuously.
+The \cleaninline{>>|.} operator denotes the sequencing of tasks in \gls{MTASK}.
\cleaninputlisting[float={!ht},linerange={23-,25-33},numbers=left,caption={The \gls{MTASK} code for the interactive blinking application.},label={lst:intro_blink_mtask}]{lst/blink.icl} %chktex 8
+\todo[inline]{Meer wit rondom =jes, doornummeren?}
\subsection{Other TOP languages}
While \gls{ITASK} conceived \gls{TOP}, it is no longer the only \gls{TOP} system.
Some \gls{TOP} languages were created to fill a gap encountered in practise.
-Toppyt \citep{lijnse_toppyt_2022} is a general purpose \gls{TOP} language written in \gls{PYTHON} used to host frameworks for modelling command \& control systems, and hTask \citep{lubbers_htask_2022}, a vessel for experimenting with asynchronous \glspl{SDS}.
+Toppyt \citep{lijnse_toppyt_2022} is a general purpose \gls{TOP} language written in \gls{PYTHON} used to host frameworks for modelling command \& control systems.
+The hTask system is a \gls{TOP} system written in \gls{HASKELL} used as a vessel for experimenting with asynchronous \glspl{SDS} \citep{lubbers_htask_2022}.
Furthermore, some \gls{TOP} systems arose from Master's and Bachelor's thesis projects.
For example, \textmu{}Task \citep{piers_task-oriented_2016}, a \gls{TOP} language for modelling non-interruptible embedded systems in \gls{HASKELL}, and LTasks \citep{van_gemert_task_2022}, a \gls{TOP} language written in the dynamically typed programming language Lua.
Finally, there are \gls{TOP} languages with strong academic foundations.
\Citeauthor{steenvoorden_tophat_2022} distinguishes two instruments for \gls{TOP}: \gls{TOP} languages and \gls{TOP} engines.
The language is the \emph{formal} language for specifying interactive systems.
The engine is the software or hardware that executes these specifications as a ready-for-work application.
+\todo[inline]{Noemen dat een vergelijkbare semantics voor mTask under construction is met een verwijzing naar de thesis van Elina?}
\section{Contributions}%
\label{sec:contributions}
%\end{itemize}
\paragraph{Contribution:}
-The papers of which I am first author are solely written by me, there were weekly meetings with co-authors in which we discussed and refined the ideas.
+The papers are written by me, there were weekly meetings with co-authors in which we discussed and refined the ideas.
\subsection{\crtCref{prt:top}: \hspace{8.28992pt}\nameref{prt:top}}
This episode is a monograph that shows the design, properties, implementation and usage of the \gls{MTASK} system and \gls{TOP} for the \gls{IOT}.