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.
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.
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.
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.
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.
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.
\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.
\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.
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.
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.
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.
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.
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.
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.
Firstly, edge devices can be seen as simple resources, thus accessed through \glspl{SDS}.
The second view is that edge devices contain miniature \gls{TOP} systems in itself.
The individual components in the miniature systems, the tasks, the \glspl{SDS}, are, in the eventual execution, connected to the main system.
Firstly, edge devices can be seen as simple resources, thus accessed through \glspl{SDS}.
The second view is that edge devices contain miniature \gls{TOP} systems in itself.
The individual components in the miniature systems, the tasks, the \glspl{SDS}, are, in the eventual execution, connected to the main system.
\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}.
\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 \citep{top_software_viia_2023}.
+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.
The framework is built on top of standard web techniques such as JavaScript, HTML, and {CSS}.
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.
The framework is built on top of standard web techniques such as JavaScript, HTML, and {CSS}.
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.
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}).
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}.
\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}
\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.
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.
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, \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.
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.
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.
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.
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.
\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}
\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}
-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 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.
\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
\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
\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.
\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.
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.
\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.
\subsection{\Fullref{prt:dsl}}
The \gls{MTASK} system is an \gls{EDSL} and during the development of it, several novel basal techniques for embedding \glspl{DSL} in \gls{FP} languages have been found.
This paper-based episode contains the following papers:
\subsection{\Fullref{prt:dsl}}
The \gls{MTASK} system is an \gls{EDSL} and during the development of it, several novel basal techniques for embedding \glspl{DSL} in \gls{FP} languages have been found.
This paper-based episode contains the following papers:
\begin{enumerate}
\item \emph{Deep Embedding with Class} \citep*{lubbers_deep_2022} is the basis for \cref{chp:classy_deep_embedding}.
It shows a novel deep embedding technique for \glspl{DSL} where the resulting language is extendible both in constructs and in interpretation just using type classes and existential data types.
\begin{enumerate}
\item \emph{Deep Embedding with Class} \citep*{lubbers_deep_2022} is the basis for \cref{chp:classy_deep_embedding}.
It shows a novel deep embedding technique for \glspl{DSL} where the resulting language is extendible both in constructs and in interpretation just using type classes and existential data types.
\Cref{sec:classy_reprise} was added after publication and contains a (yet) unpublished extension of the embedding technique for reducing the required boilerplate at the cost of requiring some advanced type system extensions.
\item \emph{First-\kern-1ptClass Data Types in Shallow Embedded Domain-Specific Languages} \citep*{lubbers_first-class_2022}\label{enum:first-class} is the basis for \cref{chp:first-class_datatypes}.
It shows how to inherit data types from the host language in \glspl{EDSL} using metaprogramming by providing a proof-of-concept implementation using \gls{HASKELL}'s metaprogramming system: \glsxtrlong{TH}.
\Cref{sec:classy_reprise} was added after publication and contains a (yet) unpublished extension of the embedding technique for reducing the required boilerplate at the cost of requiring some advanced type system extensions.
\item \emph{First-\kern-1ptClass Data Types in Shallow Embedded Domain-Specific Languages} \citep*{lubbers_first-class_2022}\label{enum:first-class} is the basis for \cref{chp:first-class_datatypes}.
It shows how to inherit data types from the host language in \glspl{EDSL} using metaprogramming by providing a proof-of-concept implementation using \gls{HASKELL}'s metaprogramming system: \glsxtrlong{TH}.
\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}.
\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}.
\subsection{\Fullref{prt:tvt}}
\Cref{prt:tvt} is based on a journal paper that quantitatively and qualitatively compares traditional \gls{IOT} architectures with \gls{TOP} \gls{IOT} architectures.
\subsection{\Fullref{prt:tvt}}
\Cref{prt:tvt} is based on a journal paper that quantitatively and qualitatively compares traditional \gls{IOT} architectures with \gls{TOP} \gls{IOT} architectures.
\item \emph{Could Tierless Programming Reduce IoT Development Grief?} \citep*{lubbers_could_2022}
is an extended version of paper~\ref{enum:iot20}.
It compares programming traditional tiered architectures to tierless architectures by illustrating a qualitative and a quantitative four-way comparison of a smart-campus application.
\item \emph{Could Tierless Programming Reduce IoT Development Grief?} \citep*{lubbers_could_2022}
is an extended version of paper~\ref{enum:iot20}.
It compares programming traditional tiered architectures to tierless architectures by illustrating a qualitative and a quantitative four-way comparison of a smart-campus application.