\usepackage{pdfpages}
\begin{document}
-\includepdf[landscape,booklet,pages={69-128}]{thesis.pdf}%chktex 29 chktex 8
-%\includepdf[landscape,booklet,pages={3-6}]{concl/concl.pdf}%chktex 29 chktex 8
+%\includepdf[landscape,booklet,pages={69-128}]{thesis.pdf}%chktex 29 chktex 8
+\includepdf[landscape,booklet,pages={1-12}]{top/finale.pdf}%chktex 29 chktex 8
%\includepdf[pages={211,212}]{thesis.pdf}%chktex 29 chktex 8
\end{document}
\end{itemize}
\item Manuscriptcommissie:
\begin{itemize}[label={}]
- \item prof.\ dr.\ S.B.\ (Sven-Bodo) Scholz
+ \item prof.\ dr.\ S.-B.\ (Sven-Bodo) Scholz
\item prof.\ dr.\ G.K.\ (Gabrielle) Keller (Universiteit Utrecht)
\item prof.\ dr.\ M.\ (Mary) Sheeran (Chalmers Tekniska H\"ogskola)
\end{itemize}
% Graphics
\usepackage{graphicx} % Images
\graphicspath{{img/},{intro/img},{top/img},{tvt/img}}
+\usepackage{dpfloat}
\usepackage{caption} % subfigures/captionof
\usepackage{subcaption}
\usepackage{rotating}
\newcommand{\Cmtask}{\Gls{CLEAN}\slash\gls{MTASK}}
\newcommand{\cimtask}{\gls{CLEAN}\slash\gls{ITASK}\slash\gls{MTASK}}
\newcommand{\Cimtask}{\Gls{CLEAN}\slash\gls{ITASK}\slash\gls{MTASK}}
-\newcommand{\ccpp}{\gls{C}\slash\gls{CPP}}
-\newcommand{\Ccpp}{\Gls{C}\slash\gls{CPP}}
+\newcommand{\ccpp}{\texorpdfstring{\gls{C}\slash\gls{CPP}}{C\slash{}C\texttt{++}}}
+\newcommand{\Ccpp}{\texorpdfstring{\Gls{C}\slash\gls{CPP}}{C\slash{}C\texttt{++}}}
\newcommand{\stacksize}[1]{\parallel#1\parallel}
\makeatletter
\section{Finale}
Traditionally, \gls{IOT} has been programmed using layered, or tiered, architectures.
Every layer has its own software and hardware characteristics, resulting in semantic friction.
-\Gls{TOP} is a declarative programming paradigm designed to describe multi-tiered interactive systems.
+\Gls{TOP} is a declarative programming paradigm designed to describe multi-tiered interactive systems from a single source.
However, it is not straightforward to run \gls{TOP} systems on resource-constrained devices such as edge devices.
The \gls{MTASK} system bridges this gap by providing a \gls{TOP} programming language for edge devices.
It integrates seamlessly in \gls{ITASK}, a \gls{TOP} system for interactive web applications.
Hence, all layers of an \gls{IOT} system can be programmed from a single declarative specification.
In \gls{ITASK}, abstraction are available for the gritty details of interactive web applications such as program distribution, web applications, data storage, and user management.
-The engine of \gls{MTASK} abstracts away of all technicalities specific to edge devices such as communication, abstractions for sensors and actuators, interrupts and (multi) task scheduling.
+The \gls{MTASK} system abstracts away of all technicalities specific to edge devices such as communication, abstractions for sensors and actuators, interrupts and (multi) task scheduling.
Any device equipped with the \gls{MTASK} \gls{RTS} can be used in the system and dynamically receive tasks for execution.
-This domain-specific \gls{OS} only needs to be programmed once, hence saving precious write cycles on the program memory.
+This domain-specific \gls{OS} only needs to be uploaded once, hence saving precious write cycles on the program memory.
The \gls{MTASK} devices are connected to the \gls{ITASK} system at run time using a single function that takes care of all the communication and error handling.
Once connected to a device, tasks written in the \gls{MTASK} \gls{DSL} can be lifted to \gls{ITASK} tasks.
The tasks are specified and compiled at run time, i.e.\ \gls{CLEAN} can be used as a macro language for constructing \gls{MTASK} tasks, tailor making them for the current work requirements.
When lifted, other tasks in the system can interact with the task through the usual means.
Furthermore, \gls{ITASK} \glspl{SDS} can be \emph{lowered} to \gls{MTASK} tasks as well, allowing for bidirectional automatic data sharing between \gls{MTASK} tasks and the \gls{ITASK} system irrespective of task relations.
-\todo{Uit\-brei\-den?}
-
-\section{Future work}
-\todo[inline]{De grens tussen future en related work is soms vaag maar ik heb het zo goed als mogelijk proberen te scheiden. Mis ik hier nog iets?}
-There are many ways of extending the research on the \gls{MTASK} system that also concerns \gls{TOP} for resource constrained devices in general.
-Some obvious routes would be to add features, support more platforms,
-\todo[inline]{meer type level dingen. Interrupts, pinmodes, \etc.}
-
-\subsection{Security}
-\Gls{IOT} has reached the news many times regarding security and it is a big concern \citep{alhirabi_security_2021}.
-The fact that the devices are embedded in the fabric, are hard to reach and thus to update, and can only run limited cryptographic algorithms due to their constrained resources makes it difficult.
-The security of \gls{MTASK} and the used protocols are deliberately overlooked at the moment
-Though, because \gls{MTASK} is modular, for example, the communication channels are communication method agnostic, it should be fairly easy to apply standard security measures to them by replacing communication methods and applying standard authentication and encryption to the protocol.
-\Citet{de_boer_secure_2020} did preliminary research on securing the communication channels, which proved to be possible without many changes in the protocol.
-Nonetheless, this deserves much more attention.
-The future and related work for the security of \gls{MTASK} and tierless systems is more thoroughly presented in \cref{ssec_t4t:security}.
-
-\subsection{Advanced edge devices techniques}
-Edge devices may produce a lot of data and it is not always effective to send this data to the server for processing.
-Leaving the produced data and computations on the edge device is called \emph{edge computing} \citep{shi_edge_2016}.
-The \gls{MTASK} exhibits many properties of edge computing because it is possible to run entire workflows on the device.
-However, it would be interesting to see how far this can be extended.
-The \gls{MTASK} language is a high-level \gls{DSL} so it would be obvious to introduce abstractions for edge computations.
-For example, add \gls{TOP} support for machine learning on the edge device using TinyML \citep{sanchez-iborra_tinyml-enabled_2020}.
-
-Another recent advance in \gls{IOT} programming is battery-less or even battery-free computing.
-Instead of equipping the edge device with a battery, a capacitor is used in conjunction with some energy harvesting systems such as a solar panel.
-With the use of intermittent computing, resuming the computation after a, possibly unexpected, power loss, operation can still be achieved \citep{hester_batteries_2019}.
-After a reset, the program state is resumed from a checkpoint that was stored in some non-volatile memory.
-Many intermittent computing solutions rely on annotations from the programmer to divide the program into atomic blocks, sometimes called \emph{tasks} as well.
-These blocks are marked as such because in the case of an reset of the system, the work must be done again.
-Examples of such blocks are \gls{I2C} transmissions or calculations that rely on recent sensor data.
-In \gls{MTASK}, all work expressed by tasks is already split up in atomic pieces of work.
-Furthermore, creating checkpoints should be fairly straightforward as \gls{MTASK} tasks do not rely on any global state---all information required to execute a task is stored in the task tree.
-It would be interesting to see what \gls{TOP} abstraction could be useful for intermittent computing and what solutions are required to make this work.
-
-Mesh networks allow for communication not only to-and-fro the device and server but also between devices.
-The \gls{ITASK} system already contains primitives for distributed operation.
-For example, it is possible to run tasks or share data with \glspl{SDS} on a different machine.
-It would be interesting to investigate how this networking technique can be utilised in \gls{MTASK}.
-
-Finally, \glspl{FPGA} have been becoming cheaper and faster recently, allowing for purely functional code to be translated to \glspl{FPGA} code efficiently \citep{baaij_digital_2015}.
-It would be interested to see how and whether (parts of) \gls{TOP} programs or the functionality of the \gls{MTASK} \gls{OS} could be translated to \gls{FPGA} specifications.
-
-\subsection{Formal semantics}
-Semantics allow reasoning about the language and programs in order do (symbolic) simulation, termination checking, task equivalence, or otherwise.
-For \gls{ITASK} there have been two attempts to formally specify the language.
-First \citet{koopman_executable_2011} defined a semantics used for property based testing based on a minimal version of \gls{ITASK}.
-Then \citet{plasmeijer_task-oriented_2012} formalised \gls{ITASK} by providing an executable semantics for the language.
-Both semantics are not suitable for formal reasoning due to the complexity.
-Later, \citet{steenvoorden_tophat_2019} created \gls{TOPHAT}, a \gls{TOP} language with a complete formal specification with similar features to \gls{MTASK} \citep{steenvoorden_tophat_2019}.
-\Citet{antonova_mtask_2022} compared parts of \gls{MTASK} to the semantics of \gls{TOPHAT} semantics and created a preliminary semantics for a subset of \gls{MTASK}.
-Future research into extending the formal semantics of \gls{MTASK} is useful to give more guarantees on \gls{MTASK} programs.
-
-\subsection{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}
-In order to keep the resource constraints low, the \gls{MTASK} language contains only a minimal set of simple task combinators.
-From these simple combinators, complex collaboration patterns can be described.
-The \gls{ITASK} language is designed exactly the opposite.
-From just a few super combinators, all other combinators are derived.
-However, this approach requires a very powerful host language in which task combinators can be defined in terms of the host language.
-It would be fruitful to investigate which workflows cannot be specified with the limited set of combinators available in \gls{MTASK}.
-Furthermore, it is unclear whether all derived combinators from \gls{ITASK} can be expressed in terms of \gls{MTASK} combinators.
-\Citet{van_der_aalst_workflow_2003} defines a benchmark set of workflow patterns.
-It would be interesting to see which patterns can be implemented with \gls{MTASK}, and what additional combinators would be needed.
-Moreover, editors are a crucial part of \gls{TOP}.
-In \gls{MTASK}, sensors can be seen as read-only shared editors that are updated by the system.
-It would be interesting to investigate how actual interactive editors would fit in \gls{MTASK}.
-For example, many smartwatches contain touch sensitive screens that could be used to interact with the user in this way.
-
-\Glspl{SDS} in \gls{ITASK} have a rich set of combinators to transform and combine the \glspl{SDS} into new \gls{SDS}.
-In \gls{MTASK}, \glspl{SDS} are just typed global variables that may or may not proxy an \gls{ITASK} \gls{SDS}.
-It would be interesting to port the \gls{SDS} combinators to \gls{MTASK} as well, allowing them to be transformed and combined also.
-
-\subsection{Usability}
-The promise of \glspl{DSL} has often been that a domain expert could program with little technical knowledge of the host programming language.
-Some even propose that a \gls{DSL} is a \gls{UI} for domain experts to computation platforms \citep{management_association_evaluating_2014}.
-In practise this is not always the case due to crippling syntax and convoluted error messages.
-Recent approaches in interactive editors for programming language source code such as dynamic editors \citep{koopman_dynamic_2021} or typed tree editors such as Hazelnut \citep{omar_hazelnut_2017} could prove useful for supporting the \gls{DSL} programmer in using \gls{MTASK}.
-If the editor produces correct \gls{MTASK} code by construction, much of the problems could be avoided.
-In the same respect, as \gls{MTASK} is a tagless-final \gls{EDSL} and uses \gls{HOAS}, the error messages are complex and larded with host language features.
-Much research has gone into simplifying these error messages by translating them to the \gls{DSL} domain, see for example \citep{serrano_type_2018}.
-A future directions could be to apply the \gls{EDSL} error message techniques on \gls{MTASK} as well.
-
-The serialisation and deserialisation of data types is automated both on the server and the \gls{MTASK} device using generic programming.
-Using the structural information of the data type, the code responsible for the functionality is automatically generated.
-Peripherals are not yet fully integrated in such a way.
-When a peripheral is added, the programmer has to define the correct byte code, implement the instructions in the interpreter, add task tree nodes, and implement them in the rewrite system.
-It would be interesting to investigate whether this can be automated or centralised in a way.
-
-\subsection{Scheduling}
-The scheduling in \gls{MTASK} works quite well but it is not real time.
-There is a variant of \gls{FRP} called \gls{PFRP} that allows for real-time operation \citep{belwal_variable_2013}.
-Furthermore, an alternative to reducing the energy consumption by going to sleep is stepping down the processor frequency.
-So called \gls{DVFS} is a scheduling technique that slows down the processor in order to reach the goals as late as possible, reducing the power consumption.
-\Citet{belwal_variable_2013} use \gls{PFRP} with \gls{DVFS} to reduce the energy consumption.
-It would be interesting to investigate the possibilities for \gls{DVFS} in \gls{MTASK} and \gls{TOP} in general.
\section{Related work}
The novelties of the \gls{MTASK} system can be compared to existing systems in several categories.
\subsection{Interpretation}\label{sec:related_int}
There are a myriad of interpreted programming languages available for some of the bigger more powerful edge devices.
For example, for the popular ESP8266 chip there are ports of \gls{MICROPYTHON}, LUA, Basic, JavaScript and Lisp.
-All of these languages, except the Lisp dialect uLisp (see \cref{sec:related_fp}), are imperative and do not support multiasking out of the box.
+All of these languages, except the Lisp dialect uLisp (see \cref{sec:related_fp}), are imperative and do not support multitasking out of the box.
They lay pretty hefty constraints on the memory and as a result do not work on smaller microcontrollers.
Another interpretation solution for the tiniest devices is Firmata, a protocol for remotely controlling the microcontroller and using a server as the interpreter host \citep{steiner_firmata:_2009}.
\citet{grebe_haskino:_2016} wrapped this in a remote monad for integration with \gls{HASKELL} that allowed imperative code to be interpreted on the microprocessors.
Later this system was extended to support multithreading as well, stepping away from Firmata as the basis and using their own \gls{RTS} \citep{grebe_threading_2019}.
It differs from our approach because continuation points need to be defined by hand there is no automatic safe data communication.
+
\Citet{baccelli_reprogramming_2018} provide a single language \gls{IOT} system based on the RIOT \gls{OS} that allows runtime deployment of code snippets called containers.
Both client and server are written in JavaScript.
However, there is no integration between the client and the server other than that they are programmed from a single source.
Regular preemptive multithreading is too memory intensive for smaller microcontrollers and therefore not suitable.
Manual interleaving of imperative code can be automated to certain extents.
Solutions often require an \gls{RTOS}, have a high memory requirement, do not support local variables, no thread-safe shared memory, no composition or no events as described in \cref{tbl:multithreadingcompare}.
-The table compares the solutions in the relevant categories with \gls{MTASK}.
+This table extends a comparison table with various solutions to multitasking to \gls{MTASK} in the relevant categories.
+\todo[inline]{Uitleg over de talen geven}
-\begin{table}[ht]
+\begin{table}
\begin{threeparttable}
\caption{%
An overview of imperative multithreading solutions for tiny computers with their relevant characteristics.
- The characteristics are: sequential execution, local variable support, parallel composition, deterministic execution, bounded execution and safe shared memory (adapted from \citet[p.\ 12]{santanna_safe_2013}).
+ The characteristics are: sequential computing, local variable support, parallel composition, deterministic execution, bounded execution and safe shared memory (adapted from \citet[p.\ 12]{santanna_safe_2013}).
}\label{tbl:multithreadingcompare}
% \begin{tabular}{lc>{\columncolor[gray]{0.95}}cc>{\columncolor[gray]{0.95}}cc>{\columncolor[gray]{0.95}}cc}
\begingroup
\end{table}
\subsection{\texorpdfstring{\Glsxtrlong{FRP}}{Functional reactive programming}}\label{sec:related_frp}
-The \gls{TOP} paradigm is often compared to \gls{FRP} and while they appear to be similar---they are both event driven---in fact they are very different.
+The \gls{TOP} paradigm is often compared to \gls{FRP} and they appear to be similar.
\Gls{FRP} was introduced by \citet{elliott_functional_1997}.
The paradigm strives to make modelling systems safer, more efficient, composable.
The core concepts are behaviours and events.
A behaviour is a value that varies over time.
Events are happenings in the real world and can trigger behaviours.
Events and behaviours may be combined using combinators.
-\Gls{TOP} allows for more complex collaboration patterns than \gls{FRP} \citep{wang_maintaining_2018}, and in consequence is unable to provide the strong guarantees on memory usage available in a restricted variant of \gls{FRP} such as arrowized \gls{FRP} \citep{nilsson_functional_2002}.
+Tasks in \gls{TOP} are also event driven and can be combined with combinators.
+\Gls{TOP} allows for more complex collaboration patterns than \gls{FRP} \citep{wang_maintaining_2018}.
+In consequence is unable to provide the strong guarantees on memory usage available in a restricted variant of \gls{FRP} such as arrowised \gls{FRP} \citep{nilsson_functional_2002}.
The way \gls{FRP}, and for that matter \gls{TOP}, systems are programmed stays close to the design when the domain matches suits the paradigm.
The \gls{IOT} domain seems to suit this style of programming very well in just the device layer but also for entire \gls{IOT} systems.
The \gls{IO} part, the bodies of some functions, still need to be implemented.
These \gls{IO} functions can then be used as signals and combined as in any \gls{FRP} language.
Due to the compilation to \gls{C} it is possible to run emfrp programs on tiny computers.
-However, the tasks are not interpreted and there is no communication with a server.
+However, in contrast to in \gls{MTASK}, the tasks are not interpreted and there is no automated communication with a server.
Other examples are CFRP \citep{suzuki_cfrp_2017}, XFRP \citep{10.1145/3281366.3281370}, Juniper \citep{helbling_juniper:_2016}, Hailstorm \citep{sarkar_hailstorm_2020}, Haski \citep{valliappan_towards_2020}, arduino-copilot \citep{hess_arduino-copilot_2020}.
They showed that applications tend to be able to cope well with interruptions and be more maintainable.
However, the hardware requirements for running the standard \gls{HASKELL} system are high.
+\section{Future work}
+There are many ways of extending the research on the \gls{MTASK} system that also concerns \gls{TOP} for resource constrained devices in general.
+Some obvious routes is to add features, support more platforms,
+
+\subsection{Security}
+\Gls{IOT} has reached the news many times regarding security and it is a big concern \citep{alhirabi_security_2021}.
+The fact that the devices are embedded in the fabric, are hard to reach and thus to update, and can only run limited cryptographic algorithms due to their constrained resources makes security difficult.
+The security of \gls{MTASK} and the used protocols are deliberately overlooked at the moment
+The \gls{MTASK} language and \gls{RTS} are modular.
+For example, the communication channels are communication method agnostic and operate through a simple duplex channel interface.
+It should therefore be fairly easy to apply standard security measures to them by replacing communication methods and applying off-the-shelve authentication and encryption to the protocol.
+\Citet{de_boer_secure_2020} did preliminary research on securing the communication channels, which proved to be possible without many changes in the protocol.
+Nonetheless, this deserves much more attention.
+The future and related work for the security of \gls{MTASK} and tierless systems is more thoroughly presented in \cref{ssec_t4t:security}.
+
+\subsection{Advanced edge devices techniques}
+Edge devices may produce a lot of data and it is not always effective to send this data to the server for processing.
+Leaving the produced data and computations on the edge device is called \emph{edge computing} \citep{shi_edge_2016}.
+The \gls{MTASK} exhibits many properties of edge computing because it is possible to run entire workflows on the device.
+However, it is interesting to see how far this can be extended.
+The \gls{MTASK} language is a high-level \gls{DSL}, so it is obvious to introduce abstractions for edge computations.
+For example, add \gls{TOP} support for machine learning on the edge device using TinyML \citep{sanchez-iborra_tinyml-enabled_2020}.
+
+Another recent advance in \gls{IOT} programming is battery-less or even battery-free computing.
+Instead of equipping the edge device with a battery, a capacitor is used in conjunction with some energy harvesting systems such as a solar panel.
+With the use of intermittent computing, resuming the computation after a, possibly unexpected, power loss, operation can still be achieved \citep{hester_batteries_2019}.
+After a reset, the program state is resumed from a checkpoint that was stored in some non-volatile memory.
+Many intermittent computing solutions rely on annotations from the programmer to divide the program into atomic blocks, sometimes called \emph{tasks} as well.
+These blocks are marked as such because in the case of an reset of the system, the work must be done again.
+Examples of such blocks are \gls{I2C} transmissions or calculations that rely on recent sensor data.
+In \gls{MTASK}, all work expressed by tasks is already split up in atomic pieces of work, i.e.\ the work is a side effect of rewriting.
+Furthermore, creating checkpoints should be fairly straightforward as \gls{MTASK} tasks do not rely on any global state---all information required to execute a task is stored in the task tree.
+It is interesting to see what \gls{TOP} abstraction could be useful for intermittent computing and what solutions are required to make this work.
+
+Mesh networks allow for communication not only to-and-fro the device and server but also between devices.
+The \gls{ITASK} system already contains primitives for distributed operation.
+For example, it is possible to run tasks or share data with \glspl{SDS} on a different machine.
+It is interesting to investigate how this networking technique can be utilised in \gls{MTASK}.
+
+Finally, \glspl{FPGA} have been becoming cheaper and faster recently, allowing for purely functional code to be translated to \glspl{FPGA} code efficiently \citep{baaij_digital_2015}.
+It would be interesting to see how and whether (parts of) \gls{TOP} programs or the functionality of the \gls{MTASK} \gls{OS} could be translated to \gls{FPGA} specifications.
+
+\subsection{Formal semantics}
+Semantics allow reasoning about the language and programs in order do (symbolic) simulation, termination checking, task equivalence, or otherwise.
+For \gls{ITASK} there have been two attempts to formally specify the language.
+First \citet{koopman_executable_2011} defined a semantics used for property based testing based on a minimal version of \gls{ITASK}.
+Then \citet{plasmeijer_task-oriented_2012} formalised \gls{ITASK} by providing an executable semantics for the language.
+Both semantics are not suitable for formal reasoning due to the complexity.
+Later, \citet{steenvoorden_tophat_2019} created \gls{TOPHAT}, a \gls{TOP} language with a complete formal specification with similar features to \gls{MTASK} \citep{steenvoorden_tophat_2019}.
+\Citet{antonova_mtask_2022} compared parts of \gls{MTASK} to the semantics of \gls{TOPHAT} semantics and created a preliminary semantics for a subset of \gls{MTASK}.
+Future research into extending the formal semantics of \gls{MTASK} is useful to give more guarantees on \gls{MTASK} programs.
+
+\subsection{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}
+In order to keep the resource constraints low, the \gls{MTASK} language contains only a minimal set of simple task combinators.
+From these simple combinators, complex collaboration patterns can be described.
+The \gls{ITASK} language is designed exactly the opposite.
+From just a few super combinators, all other combinators are derived.
+However, this approach requires a very powerful host language in which task combinators can be defined in terms of the host language.
+It could be fruitful to investigate which workflows cannot be specified with the limited set of combinators available in \gls{MTASK}.
+Furthermore, it is unclear whether all derived combinators from \gls{ITASK} can be expressed in terms of \gls{MTASK} combinators.
+\Citet{van_der_aalst_workflow_2003} defines a benchmark set of workflow patterns.
+It is interesting to see which patterns can be implemented with \gls{MTASK}, and what additional combinators are needed.
+Moreover, editors are a crucial part of \gls{TOP}.
+In \gls{MTASK}, sensors can be seen as read-only shared editors that are updated by the system.
+It is interesting to investigate how actual interactive editors would fit in \gls{MTASK}.
+For example, many smartwatches contain touch sensitive screens that could be used to interact with the user in this way.
+Alternatively, sufficiently powerful edge devices can probably run simple web interfaces as well.
+
+\Glspl{SDS} in \gls{ITASK} have a rich set of combinators to transform and combine the \glspl{SDS} into new \gls{SDS}.
+In \gls{MTASK}, \glspl{SDS} are typed global variables that may or may not proxy an \gls{ITASK} \gls{SDS}.
+It could be interesting to port the \gls{SDS} combinators to \gls{MTASK} as well, allowing them to be transformed and combined also.
+
+\subsection{Usability}
+The promise of \glspl{DSL} has often been that a domain expert could program with little technical knowledge of the host programming language.
+Some even propose that a \gls{DSL} is a \gls{UI} for domain experts to computation platforms \citep{management_association_evaluating_2014}.
+In practise this is not always the case due to crippling syntax and convoluted error messages.
+Recent approaches in interactive editors for programming language source code such as dynamic editors \citep{koopman_dynamic_2021} or typed tree editors such as Hazelnut \citep{omar_hazelnut_2017} could prove useful for supporting the \gls{DSL} programmer in using \gls{MTASK}.
+If the editor produces correct \gls{MTASK} code by construction, much of the problems could be avoided.
+In the same respect, as \gls{MTASK} is a tagless-final \gls{EDSL} and uses \gls{HOAS}, the error messages are complex and larded with host language features.
+Much research has gone into simplifying these error messages by translating them to the \gls{DSL} domain, see for example \citep{serrano_type_2018}.
+De Roos briefly investigated these methods in their research internship.
+A future directions could be to extend these findings and apply more \gls{EDSL} error message techniques on \gls{MTASK} as well.
+
+The serialisation and deserialisation of data types is automated both on the server and the \gls{MTASK} device using generic programming.
+Using the structural information of the data type, the code responsible for the functionality is automatically generated.
+Peripherals are not yet fully integrated in such a way.
+When a peripheral is added, the programmer has to define the correct byte code, implement the instructions in the interpreter, add task tree nodes, and implement them in the rewrite system.
+It would be interesting to investigate whether this can be automated or centralised in a way.
+
+More elaborate features in the type systems of modern functional programming languages allow for more type safety.
+The \gls{MTASK} language relies a lot on these features such as (multi-parameter) type classes and existential data types with class constraints.
+However, it should be possible to make abstractions over more stuff to make it safer.
+For example, the pin mode could be made a type parameter of the \gls{GPIO} pins, or interrupt handling could be made safer by incorporating the capabilities of the devices.
+
+\subsection{Scheduling}
+The scheduling in \gls{MTASK} works quite well but it is not real time.
+There is a variant of \gls{FRP} called \gls{PFRP} that allows for real-time operation \citep{belwal_variable_2013}.
+Furthermore, an alternative to reducing the energy consumption by going to sleep is stepping down the processor frequency.
+So called \gls{DVFS} is a scheduling technique that slows down the processor in order to reach the goals as late as possible, reducing the power consumption.
+\Citet{belwal_variable_2013} use \gls{PFRP} with \gls{DVFS} to reduce the energy consumption.
+It is interesting to investigate the possibilities for \gls{DVFS} in \gls{MTASK} and \gls{TOP} in general.
+
\section{History of \texorpdfstring{\gls{MTASK}}{mTask}}
The development of \gls{MTASK} or its predecessors has been going on for almost seven years now though it really set off during my master's thesis.
+Many colleagues and students have worked on aspects of the \gls{MTASK} system in collaborations, internships and Bachelor and Master's theses.
This section provides an exhaustive overview of the work on \gls{MTASK} and its predecessors.
-\subsection{Generating \texorpdfstring{\ccpp{}}{\ccpp{}} code}
+\subsection{Generating \ccpp{} code}
A first throw at a class-based shallowly \gls{EDSL} for microcontrollers was made by \citet{plasmeijer_shallow_2016}.
The language was called \gls{ARDSL} and offered a type safe interface to \gls{ARDUINO} \gls{CPP} dialect.
A \gls{CPP} code generation backend was available together with an \gls{ITASK} simulation backend.
\subsection{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}
In 2022, the SusTrainable summer school in Rijeka, Croatia hosted a course on developing greener \gls{IOT} applications using \gls{MTASK} as well \citep{lubbers_green_2022}.
Several students worked on extending \gls{MTASK} with many useful features:
-\Citet{van_der_veen_mutable_2020} did preliminary work on a green computing analysis, built a simulator, and explored the possibilities for adding bounded datatypes; \citet{de_boer_secure_2020} investigated the possibilities for secure communication channels; \citeauthor{crooijmans_reducing_2021} \citeyearpar{crooijmans_reducing_2021,crooijmans_reducing_2022} added abstractions for low-power operation to \gls{MTASK} such as hardware interrupts and power efficient scheduling; and \citet{antonova_mtask_2022} defined a preliminary formal semantics for a subset of \gls{MTASK}.
+\Citet{van_der_veen_mutable_2020} did preliminary work on a green computing analysis, built a simulator, and explored the possibilities for adding bounded datatypes; de Roos explored beautifying error messages; \citet{de_boer_secure_2020} investigated the possibilities for secure communication channels; \citeauthor{crooijmans_reducing_2021} \citeyearpar{crooijmans_reducing_2021,crooijmans_reducing_2022} added abstractions for low-power operation to \gls{MTASK} such as hardware interrupts and power efficient scheduling; and \citet{antonova_mtask_2022} defined a preliminary formal semantics for a subset of \gls{MTASK}.
In 2023, the SusTrainable summer school in Coimbra, Portugal will host a course on \gls{MTASK} as well.
\subsection{\texorpdfstring{\gls{MTASK}}{mTask} in practise}
\chapter{Integration of \texorpdfstring{\gls{MTASK}}{mTask} and \texorpdfstring{\gls{ITASK}}{iTask}}%
\label{chp:integration_with_itask}
\begin{chapterabstract}
- This chapter shows the integration of \gls{MTASK} with \gls{ITASK} by showing:
+ This chapter shows the integration of \gls{MTASK} and \gls{ITASK} by showing:
\begin{itemize}
- \item an architectural overview \gls{MTASK} applications;
- \item on the interface for connecting devices;
+ \item an architectural overview of \gls{MTASK} applications;
+ \item the interface for connecting devices;
\item the interface for lifting \gls{MTASK} tasks to \gls{ITASK} tasks;
\item a interface for lowering \gls{ITASK} \glspl{SDS} to \gls{MTASK} \glspl{SDS};
- \item and finishes with non-trivial home automation example application using all integration mechanisms;
+ \item and a non-trivial home automation example application using all integration mechanisms;
\end{itemize}
\end{chapterabstract}
The \gls{MTASK} language is a multi-view \gls{DSL}, there are multiple interpretations possible for a single \gls{MTASK} term.
-Using the byte code compiler (\cleaninline{BCInterpret}) \gls{DSL} interpretation, \gls{MTASK} tasks are fully integrated in \gls{ITASK}.
-They are executed as if they are regular \gls{ITASK} tasks and they can access \glspl{SDS} from \gls{ITASK}.
-Devices in the \gls{MTASK} system contain a domain-specific \gls{OS} and are little \gls{TOP} engines in their own respect, being able to execute tasks.
+When using the byte code compiler (\cleaninline{BCInterpret}) \gls{DSL} interpretation, \gls{MTASK} tasks are fully integrated in \gls{ITASK}.
+They execute as regular \gls{ITASK} tasks and they can access \glspl{SDS} from \gls{ITASK}.
+Devices in the \gls{MTASK} system are set up with a domain-specific \gls{OS} and become little \gls{TOP} engines in their own respect, being able to execute tasks.
\Cref{fig:mtask_integration} shows the architectural layout of a typical \gls{IOT} system created with \gls{ITASK} and \gls{MTASK}.
The entire system is written as a single \gls{CLEAN} specification where multiple tasks are executed at the same time.
Tasks can access \glspl{SDS} according to many-to-many communication and multiple clients can work on the same task.
The diagram contains three labelled arrows that denote the integration functions between \gls{ITASK} and \gls{MTASK}.
-Devices are integrated into the system using the \cleaninline{withDevice} function (see \cref{sec:withdevice}).
+Devices are connected to the system using the \cleaninline{withDevice} function (see \cref{sec:withdevice}).
Using \cleaninline{liftmTask}, \gls{MTASK} tasks are lifted to a device (see \cref{sec:liftmtask}).
\glspl{SDS} from \gls{ITASK} are lowered to the \gls{MTASK} device using \cleaninline{lowerSds} (see \cref{sec:liftsds}).
\begin{figure}
\centering
\includestandalone{mtask_integration}
-\caption{An architectural view of an \imtask{} applications.}%
+ \caption{An architectural overview of an \imtask{} application.}%
\label{fig:mtask_integration}
\end{figure}
\section{Connecting edge devices}\label{sec:withdevice}
Edge devices in an \gls{MTASK} application are always coordinated by a server.
-This means that they wait for a server to connect to them and send work.
-The heavy lifting of connecting an \gls{MTASK} device to an \gls{ITASK} server is done with the \cleaninline{withDevice} function.
-This function is given a communication specification and a function producing an \gls{ITASK} task that does something with an \gls{MTASK} device, e.g.\ lift tasks.
+This means that they wait for a server to take initiative, set up a connection, and send the work.
+The heavy lifting of connecting an \gls{MTASK} device to an \gls{ITASK} server is done with the \cleaninline{withDevice} \gls{ITASK} function.
+This function has two parameters, a communication specification, and a function using a device handle.
+The device handle is required to interact with \gls{MTASK} devices, e.g.\ lift tasks.
By using \gls{HOAS} like this, setting up and tearing down the connection to the device is fully controlled.
-In the implementation of the function, all communication with a device happens through a so-called \emph{channels} \gls{SDS}.
-The channels contain three fields, a queue of messages that are received, a queue of messages to send and a stop flag.
+All communication with a device happens through a so-called \emph{channels} \gls{SDS}.
+The channels contain three fields, a queue of messages that are received, a queue of messages to send, and a stop flag.
Every communication method that implements the \cleaninline{channelSync} class can provide the communication with an \gls{MTASK} device.
-As of now, serial port communication, direct \gls{TCP} communication and \gls{MQTT} over \gls{TCP} are supported as communication providers (see \cref{lst:connection_types}).
+At the time of writing, serial port, direct \gls{TCP}, and \gls{MQTT} over \gls{TCP} are supported communication methods (see \cref{lst:connection_types}).
Internally, the \cleaninline{withDevice} task sets up the communication, exchanges specifications with the device, executes the inner task while handling errors, and finally cleans up after closing.
-\Cref{lst:mtask_device} shows the types and interface to connecting devices.
+\Cref{lst:mtask_device} shows the types and interface for connecting devices.
\begin{lstClean}[label={lst:mtask_device},caption={Device communication interface in \gls{MTASK}.}]
:: MTDevice //abstract
The first \gls{SDS} is the information about the \gls{RTS} of the device, i.e.\ metadata on the tasks that are executing, the hardware specification and capabilities, and a list of fresh task identifiers.
The second \gls{SDS} is a map storing downstream \gls{SDS} updates.
When a lowered \gls{SDS} is updated on the device, a message is sent to the server.
-This message is initially queued in the map to allow for asynchronous handling of multiple updates.
+This message is initially queued in the map in order to properly handly multiple updates asychronously.
Finally, the \cleaninline{MTDevices} type contains the communication channels.
-The \cleaninline{withDevice} task itself first constructs the \glspl{SDS} using the \gls{ITASK} function \cleaninline{withShared} to create anonymous local \glspl{SDS}.
+The \cleaninline{withDevice} task itself first constructs the \glspl{SDS} using the \gls{ITASK} function \cleaninline{withShared}.
Then, it performs the following four tasks in parallel to monitor the edge device.
\begin{enumerate}
- \item It synchronises the channels using the \cleaninline{channelSync} overloaded function.
- Errors that occur here are converted to the proper \gls{MTASK} exception.
- \item Watches the channels for the shutdown flag.
+ \item The channels are synchronised using the overloaded \cleaninline{channelSync} function.
+ Errors that occur here are converted to the proper \gls{MTASK} or \gls{ITASK} exception.
+ \item The shutdown flag of the channels is watched.
If the connection is lost with the device unexpectedly, an \gls{MTASK} exception is thrown.
- \item Watches the channels for messages and processes them accordingly by changing the device information \gls{SDS} or adding the lowered \gls{SDS} updates to the corresponding \gls{SDS} update queue.
- \item Sends a request for a specification. Once the specification is received, the device task is run.
+ \item The received messages in the channels are watched and processed.
+ Depending on the type of message, either the device information \gls{SDS} is updated, or the \gls{SDS} update is added to the lowered \gls{SDS} updates \gls{SDS}.
+ \item A request for a specification is sent.
+ Once the specification is received, the device task is run.
The task value of this device task is then used as the task value of the \cleaninline{withDevice} task.
\end{enumerate}
-\begin{lstClean}[caption={Pseudocode for the \texttt{widthDevice} function},label={lst:pseudo_withdevice}]
+\begin{lstClean}[caption={Pseudocode for the \texttt{withDevice} function in \gls{MTASK}.},label={lst:pseudo_withdevice}]
withDevice spec deviceTask =
+ withShared default \dev->parallel
withShared newMap \sdsupdates->
withShared ([], [MTTSpecRequest], False) \channels->
- withShared default \dev->parallel
[ channelSync spec channels
, watchForShutdown channels
, watchChannelMessages dev channels
, waitForSpecification
- >>| deviceTask
+ >>| deviceTask (MTDevice dev sdsupdates channels)
>>* [ifStable: issueShutdown]
]
\end{lstClean}
-If at any stage an unrecoverable device error occurs, an \gls{ITASK} exception is thrown on the \cleaninline{withDevice} task.
+If at any stage an unrecoverable device error occurs, an \gls{ITASK} exception is thrown in the \cleaninline{withDevice} task.
This exception can be caught in order to devise fail-safe mechanisms.
For example, if a device fails, the task can be sent to another device as can be seen in \cref{lst:failover}.
This function executes an \gls{MTASK} task on a pool of devices connected through \gls{TCP}.
-If a device error occurs during execution, the next device in the pool is tried until the pool is exhausted
-If another error occurs, it is rethrown for a parent task to catch.
+If a device error occurs during execution, the next device in the pool is tried until the pool is exhausted.
+If another type of error occurs, it is rethrown for a parent task to catch.
\begin{lstClean}[caption={An \gls{MTASK} failover combinator.},label={lst:failover}]
-failover :: [TCPSettings] (Main (MTask BCInterpret a)) -> Task a
-failover [] _ = throw "Exhausted device pool"
-failover [d:ds] mtask = try (withDevice d (liftmTask mtask)) except
-where except MTEUnexpectedDisconnect = failover ds mtask
- except _ = throw e
+ failover :: [TCPSettings] (Main (MTask BCInterpret a)) -> Task a
+ failover [] _ = throw "Exhausted device pool"
+ failover [d:ds] mtask = try (withDevice d (liftmTask mtask)) except
+ where except MTEUnexpectedDisconnect = failover ds mtask
+ except _ = throw e
\end{lstClean}
\section{Lifting \texorpdfstring{\gls{MTASK}}{mTask} tasks}\label{sec:liftmtask}
-Once the connection with the device is established, \gls{MTASK} tasks are lifted to \gls{MTASK} tasks using the \cleaninline{liftmTask} family of functions (see \cref{lst:liftmtask}).
-Given an \gls{MTASK} task in the \cleaninline{BCInterpret} view and a device obtained from \cleaninline{withDevice}, an \gls{ITASK} task is returned.
+Once the connection with the device is established, \gls{MTASK} tasks are lifted to \gls{ITASK} tasks using the \cleaninline{liftmTask} function (see \cref{lst:liftmtask}).
+Given an \gls{MTASK} task in the \cleaninline{BCInterpret} view and a device handle obtained from \cleaninline{withDevice}, an \gls{ITASK} task is returned.
This \gls{ITASK} task proxies the \gls{MTASK} task that is executed on the microcontroller.
-Hence, when for example observing the task value, the actual task value from the microcontroller is observed.
+So, when another task observes the task value, the actual task value from the microcontroller is observed.
\begin{lstClean}[label={lst:liftmtask},caption={The interface for lifting \gls{MTASK} tasks to \gls{ITASK} tasks.}]
liftmTask :: (Main (MTask BCInterpret a)) MTDevice -> Task a | iTask a
\subsection{Implementation}
\Cref{lst:liftmTask_pseudo} shows the pseudocode for the \cleaninline{liftmTask} implementation
-The first argument is the task and the second argument is the device which is just an \gls{ADT} containing the \glspl{SDS} referring to the device information, the \gls{SDS} update queue, and the channels.
+The first argument is the task and the second argument is the device which is an \gls{ADT} containing the \glspl{SDS} referring to the device information, the \gls{SDS} update queue, and the channels.
First a fresh identifier for the task is generated using the device state.
With this identifier, the cleanup hook can be installed.
This is done to assure the task is removed from the edge device if the \gls{ITASK} task coordinating it is destroyed.
-Tasks in \gls{ITASK} are destroyed when for example it is executed in parallel with another task and the parallel combinator terminates or when the condition to step holds in a sequential task combination.
+Tasks in \gls{ITASK} are destroyed when for example it is executed in parallel with another task and the parallel combinator terminates, or when the condition to step holds in a sequential task combination.
Then the \gls{MTASK} compiler is invoked, its only argument besides the task is a function doing something with the results of the compilation, i.e.\ the lowered \glspl{SDS} and the messages containing the compiled and serialised task.
With the result of the compilation, the task can be executed.
First the messages are put in the channels, sending them to the device.
Then, in parallel:
-\begin{enumerate*}
- \item the value is watched by looking in the device state \gls{SDS}, this task also determines the task value of the whole task
- \item the downstream \glspl{SDS} are monitored, i.e.\ the \cleaninline{sdsupdates} \gls{SDS} is monitored and updates from the device are applied to the associated \gls{ITASK} \gls{SDS}
- \item the upstroam \glspl{SDS} are monitored by spawning tasks that watch these \glspl{SDS}, if one is updated, the novel value is sent to the edge device.
-\end{enumerate*}
+\begin{enumerate}
+ \item the value is watched by looking in the device state \gls{SDS}, this task also determines the task value of the whole task;
+ \item the downstream \glspl{SDS} are monitored, i.e.\ the \cleaninline{sdsupdates} \gls{SDS} is monitored and updates from the device are applied to the associated \gls{ITASK} \gls{SDS};
+ \item the upstream \glspl{SDS} are monitored by spawning tasks that watch these \glspl{SDS}, if one is updated, the novel value is sent to the edge device.
+\end{enumerate}
\begin{lstClean}[label={lst:liftmTask_pseudo},caption={Pseudocode implementation for \texttt{liftmTask}.}]
liftmTask task (MTDevice dev sdsupdates channels)
\end{lstClean}
Sending the complete byte code to the device is not always a suitable option.
-For example, when the device is connected through an unstable or slow connection, sending the entire byte code may induce lots of delay.
+For example, when the device is connected through an unstable or slow connection, sending the entire byte code induces a lot of delay.
To mitigate this problem, \gls{MTASK} tasks can be preloaded on a device.
Preloading means that the task is compiled and integrated into the device firmware.
On receiving a \cleaninline{TaskPrep}, a hashed value of the task to be sent is included.
-The device then checks the preloaded task registry and uses the local version if the hash matches.
+The device then checks the preloaded task registry and uses the local preloaded version if the hash matches.
Of course this only works for tasks that are not tailor made for the current work specification and not depend on run time information.
The interface for task preloading can be found in \cref{lst:preload}.
-Given an \gls{MTASK} task, a header file is created that is placed in the source code directory of the \gls{RTS} to include it in the firmware.
+Given an \gls{MTASK} task, a header file is created that should be placed in the source code directory of the \gls{RTS} before building to include it in the firmware.
\begin{lstClean}[label={lst:preload},caption={Preloading tasks in \gls{MTASK}.}]
-preloadTask :: (Main (MTask BCInterpret u)) -> Task String
+preloadTask :: (Main (MTask BCInterpret a)) -> Task String
\end{lstClean}
\section{Lowering \texorpdfstring{\gls{ITASK}}{iTask} \texorpdfstring{\glsxtrlongpl{SDS}}{shared data sources}}\label{sec:liftsds}
-Lowering \gls{ITASK} \glspl{SDS} to \gls{MTASK} \glspl{SDS} is something that mostly happens at the compiler level using the \cleaninline{lowerSds} function (see \cref{lst:mtask_itasksds}).
-\Glspl{SDS} in \gls{MTASK} must always have an initial value.
+Lowering \gls{ITASK} \glspl{SDS} to \gls{MTASK} \glspl{SDS} is something that mostly happens at the \gls{DSL} level using the \cleaninline{lowerSds} function (see \cref{lst:mtask_itasksds}).
+Lowering \pgls{SDS} proxies the \gls{ITASK} \gls{SDS} for use in \gls{MTASK}.
+\Glspl{SDS} in \gls{MTASK} always have an initial value.
For regular \gls{SDS} this value is given in the source code, for lowered \gls{ITASK} \glspl{SDS} this value is obtained by reading the values once just before sending the task to the edge device.
-On the device itself, there is just one difference between lowered \glspl{SDS} and regular \glspl{SDS}: after changing \pgls{SDS}, a message is sent to the server containing this new value.
+On the device, there is just one difference between lowered \glspl{SDS} and regular \glspl{SDS}: after changing a lowered \gls{SDS}, a message is sent to the server containing this new value.
The \cleaninline{withDevice} task (see \cref{sec:withdevice}) receives and processes this message by writing to the \gls{ITASK} \gls{SDS}.
Tasks watching this \gls{SDS} get notified then through the normal notification mechanism of \gls{ITASK}.
The \gls{MTASK} task uses this \gls{SDS} to turn on or off the light.
The \gls{ITASK} task that runs in parallel allows interactive updating of this state.
-\begin{lstClean}[label={lst:mtask_liftsds_ex},caption={Interactive light switch program.}]
+\begin{lstClean}[label={lst:mtask_liftsds_ex},caption={Interactive light switch program in \gls{MTASK}.}]
lightswitch :: MTDevice -> Task Bool
-lightswitch dev =
- withShared False \sh->
+lightswitch dev = withShared False \sh->
liftmTask (mtask sh) dev
-|| updateSharedInformation [] sh
<<@ Hint "Light switch"
lowerSds \ls=sh
In fun \f=(\st->
getSds ls
- >>*. [IfValue ((!=.)st) (\v->writeD d13 v)]
+ >>*. [IfValue (\v->v !=. st) (\v->writeD d13 v)]
>>|. f (Not st))
In {main=f true}
\end{lstClean}
\subsection{Implementation}
The compilation of the code and the serialisation of the data throws away all typing information.
\Glspl{SDS} are stored in the compiler state as a map from identifiers to either an initial value or an \cleaninline{MTLens}.
-The \cleaninline{MTLens} is a type synonym for a \gls{SDS} that represents the typeless serialised value of the underlying \gls{SDS}.
-This is done so that the \cleaninline{withDevice} task can write the received \gls{SDS} updates to the according \gls{SDS} independently.
+The \cleaninline{MTLens} is a type synonym for \pgls{SDS} that represents the typeless serialised value of the underlying \gls{SDS}.
+This is done so that the \cleaninline{withDevice} task can write the received \gls{SDS} updates to the according \gls{SDS} while the \gls{SDS} is not in scope.
The \gls{ITASK} notification mechanism then takes care of the rest.
Such \pgls{SDS} is created by using the \cleaninline{mapReadWriteError} which, given a pair of read and write functions with error handling, produces \pgls{SDS} with the lens embedded.
The read function transforms converts the typed value to a typeless serialised value.
-The write function will, given the new serialised value and the old typed value, produce a new typed value.
+The write function will, given a new serialised value and the old typed value, produce a new typed value.
It tries to decode the serialised value, if that succeeds, it is written to the underlying \gls{SDS}, an error is thrown otherwise.
-\Cref{lst:mtask_itasksds_lens} provides the implementation for this:
+\Cref{lst:mtask_itasksds_lens} shows the implementation for this.
% VimTeX: SynIgnore on
\begin{lstClean}[label={lst:mtask_itasksds_lens},caption={Lens applied to lowered \gls{ITASK} \glspl{SDS} in \gls{MTASK}.}]
This identifier is then used to provide a reference to the \cleaninline{def} definition to evaluate the main expression.
% VimTeX: SynIgnore on
-\begin{lstClean}[label={lst:mtask_itasksds_lift},caption={Lens applied to lowered \gls{ITASK} \glspl{SDS} in \gls{MTASK}.}]
+\begin{lstClean}[label={lst:mtask_itasksds_lift},caption={The implementation for lowering \glspl{SDS} in \gls{MTASK}.}]
instance lowerSds BCInterpret where
lowerSds def = {main =
let (t In _) = def (abort "lowerSds: expression too strict")
}\end{lstClean}
% VimTeX: SynIgnore off
+\section{Conclusion}
+When \gls{IOT} edge devices run the \gls{MTASK} \gls{RTS}, they become little \gls{TOP} engines of their own.
+Using just three \gls{ITASK} functions, \gls{MTASK} devices are integrated in \gls{ITASK} seamlessly.
+Devices, using any supported type of connection, are integrated in \gls{ITASK} using the \cleaninline{withDevice} function.
+Once connected, \gls{MTASK} tasks are sent to the device for execution using \cleaninline{liftmTask}, lifting them to full-fledged \gls{ITASK} tasks.
+To lower the bandwidth, tasks can also be preloaded.
+Furthermore, the \gls{MTASK} tasks interact with \gls{ITASK} \glspl{SDS} using the \cleaninline{lowerSds} construct.
+All of this together allows programming all layers of an \gls{IOT} system from a single source and in a single paradigm.
+All details regarding interoperation are automatically taken care of.
+The following section contains an elaborate example using all integration functions that has deliberately been placed after the conclusion so that the code listing and description are on facing pages.
+
+\begin{figure}[p]
+ \begin{leftfullpage}
+ \vspace{\headsep}
\section{Home automation}
-\todo[inline]{Staat dit hier goed of moet dit naar een andere sectie?}
-This section presents a interactive home automation program (\Cref{lst:example_home_automation}) to illustrate \gls{MTASK}'s integration with \gls{ITASK}.
-It consists of a web interface for the user to control which tasks may be executed on either of two connected devices: an \gls{ARDUINO} UNO, connected via a serial port; and an ESP8266 based prototyping board called NodeMCU, connected via \gls{TCP} over \gls{WIFI}.
+This section presents an interactive home automation program (\cref{lst:example_home_automation}) to illustrate the integration of the \gls{MTASK} language and the \gls{ITASK} system.
+It consists of a web interface for the user to control which tasks are executed on either one of two connected devices: an \gls{ARDUINO} UNO, connected via a serial port; and an ESP8266 based prototyping board called NodeMCU, connected via \gls{TCP} over \gls{WIFI}.
\Crefrange{lst:example:spec1}{lst:example:spec2} show the specification for the devices.
The UNO is connected via serial using the unix filepath \path{/dev/ttyACM0} and the default serial port settings.
Both types have \cleaninline{channelSync} instances.
The code consists of an \gls{ITASK} part and several \gls{MTASK} parts.
-\Crefrange{lst:example:task1}{lst:example:task2} containing the \gls{ITASK} task that coordinates the \gls{IOT} application.
-It first connects the devices (\crefrange{lst:example:conn1}{lst:example:conn2}) followed by launching a \cleaninline{parallel} task, visualized as a tabbed window, and a shutdown button to terminate the program (\crefrange{lst:example:par1}{lst:example:par2}).
+\Crefrange{lst:example:task1}{lst:example:task2} contains the \gls{ITASK} task that coordinates the \gls{IOT} application.
+First the devices are connected (\crefrange{lst:example:conn1}{lst:example:conn2}) followed by launching a \cleaninline{parallel} task, visualized as a tabbed window, and a shutdown button to terminate the program (\crefrange{lst:example:par1}{lst:example:par2}).
This parallel task is the controller of the tasks that run on the edge devices.
It contains one task that allows adding new tasks (using \cleaninline{appendTask}) and all other tasks in the process list will be \gls{MTASK} tasks once they are added by the user.
-The controller task, \cleaninline{chooseTask} as shown in \crefrange{lst:example:ct1}{lst:example:ct2}, allows the user to pick a task, sending it to the specified device.
+The controller task, \cleaninline{chooseTask} as shown in \crefrange{lst:example:ct1}{lst:example:ct2}, allows the user to pick a task, and sending it to the specified device.
Tasks are picked by index from the \cleaninline{tasks} list (\crefrange{lst:example:tasks1}{lst:example:tasks2}) using \cleaninline{enterChoice}.
-The interface that is generated for this can be seen in \cref{fig:example_screenshots1}.
+The interface that is generated for this is seen in \cref{fig:example_screenshots1}.
After selecting the task, a device is selected (see \cref{fig:example_screenshots2,lst:example:selectdev}).
-When both a task and a device is selected, an \gls{ITASK} task is added to the process list using \cleaninline{appendTask}.
-Using the helper function \cleaninline{mkTask}, the actual task is selected from the \cleaninline{tasks} list and executed by providing the device argument.
+When both a task and a device are selected, an \gls{ITASK} task is added to the process list using \cleaninline{appendTask}.
+Using the helper function \cleaninline{mkTask}, the actual task is selected from the \cleaninline{tasks} list and executed by providing it the device argument.
For example, when selecting the \cleaninline{temperature} task, the current temperature is shown to the user (\cref{fig:example_screenshots3}).
-This task just sends a simple temperature monitoring task to the device using \cleaninline{liftmTask} and provides a view on its task value using the \cleaninline{>\&>}\footnotemark{} \gls{ITASK} combinator.
-\footnotetext{\cleaninline{(>\&>) infixl 1 :: (Task a) ((SDSLens () (? a) ()) -> Task b) -> Task b \| iTask a \& iTask b}}
+This task just sends a simple temperature monitoring task to the device using \cleaninline{liftmTask} and provides a view on its task value using the \cleaninline{>\&>} \gls{ITASK} combinator.
+This combinator allows the observation of the left-hand side task's value through \pgls{SDS}.
The light switch task at \crefrange{lst:example:ls1}{lst:example:ls2} is a task that has bidirectional interaction using the definition of \cleaninline{lightswitch} shown in \cref{lst:mtask_liftsds_ex}.
Using \cleaninline{liftsds}, the status of the light switch is synchronised with the user.
-The task on the edge device continuously monitors the value of the lowered \gls{SDS}.
-If it is different from the current state, the new value is written to the digital \gls{GPIO} pin 13 and the monitoring function is recursively called.
-
-\begin{figure}[ht]
- \centering
- \begin{subfigure}[b]{.3\linewidth}
- \includegraphics[width=\linewidth]{home_auto1}
- \caption{Select task.}%
- \label{fig:example_screenshots1}
- \end{subfigure}
- \begin{subfigure}[b]{.3\linewidth}
- \includegraphics[width=\linewidth]{home_auto2}
- \caption{Select device.}%
- \label{fig:example_screenshots2}
- \end{subfigure}
- \begin{subfigure}[b]{.3\linewidth}
- \includegraphics[width=\linewidth]{home_auto3}
- \caption{View result.}%
- \label{fig:example_screenshots3}
- \end{subfigure}
- \caption{Screenshots of the home automation example program in action.}%
- \label{fig:example_screenshots}
+Finally, a task that calculates the factorial of a user-provided number is shown in the list.
+
+ \vspace{4ex}
+ \begin{center}
+ \begin{subfigure}[b]{.3\linewidth}
+ \includegraphics[width=\linewidth]{home_auto1}
+ \caption{Select task.}%
+ \label{fig:example_screenshots1}
+ \end{subfigure}
+ \begin{subfigure}[b]{.3\linewidth}
+ \includegraphics[width=\linewidth]{home_auto2}
+ \caption{Select device.}%
+ \label{fig:example_screenshots2}
+ \end{subfigure}
+ \begin{subfigure}[b]{.3\linewidth}
+ \includegraphics[width=\linewidth]{home_auto3}
+ \caption{View result.}%
+ \label{fig:example_screenshots3}
+ \end{subfigure}
+ \caption{Screenshots of the home automation example program in action.}%
+ \label{fig:example_screenshots}
+ \end{center}
+ \end{leftfullpage}
\end{figure}
-\begin{figure}
- \cleaninputlisting[firstline=12,lastline=50,numbers=left,belowskip=0pt]{lst/example.icl}
- \begin{lstClean}[numbers=left,firstnumber=40,aboveskip=0pt,caption={An example of a home automation program.},label={lst:example_home_automation}]
+\begin{figure}[p]
+ \begin{fullpage}
+ \cleaninputlisting[firstline=12,lastline=50,numbers=left,belowskip=0pt]{lst/example.icl}
+ \begin{lstClean}[numbers=left,firstnumber=40,aboveskip=0pt,caption={An example of a home automation program.},label={lst:example_home_automation}]
, ...][+\label{lst:example:tasks2}+]\end{lstClean}
+ \end{fullpage}
\end{figure}
-\section{Conclusion}
-When \gls{IOT} edge devices run the \gls{MTASK} \gls{RTS}, they become little \gls{TOP} engines of their own.
-Using just three \gls{ITASK} functions, \gls{MTASK} devices are integrated in \gls{ITASK} seamlessly.
-Devices, using any supported type of connection, are integrated in \gls{ITASK} using the \cleaninline{withDevice} function.
-Once connected, \gls{MTASK} tasks are sent to the device for execution using \cleaninline{liftmTask}, lifting them to full-fledged \gls{ITASK} tasks.
-To lower the bandwidth, tasks can also be preloaded.
-Furthermore, the \gls{MTASK} tasks interact with \gls{ITASK} \glspl{SDS} using the \cleaninline{lowerSds} construct.
-All of this together allows programming all layers of an \gls{IOT} system from a single source and in a single paradigm.
-All details regarding interoperation are automatically taken care of.
-
\input{subfilepostamble}
\end{document}
{main=temperature dht}
) dev
>&> \t->viewSharedInformation
- [ViewAs \i->toString (fromMaybe 0.0 i) +++ "C"] t
+ [ViewAs \i->toString (fromMaybe 0.0 i) +++ "C"] t
<<@ Hint "Current Temperature" @! ())
, ("lightswitch", \dev-> /*\label{lst:example:ls1}*/
withShared False \sh->
- liftmTask (lightswitch sh) dev
+ liftmTask (lightswitch sh) dev
-|| updateSharedInformation [] sh <<@ Hint "Switch")/*\label{lst:example:ls2}*/
, ("factorial", \dev->
- updateInformation [] 5 <<@ Hint "Factorial of what?"
+ updateInformation [] 5 <<@ Hint "Factorial of what?"
>>? \i->liftmTask (factorial i) dev
>>- \r->viewInformation [] r <<@ Hint "Result" @! ())
]
\node (CN) [client,inner sep=0pt,draw,right=of CD] {Client\textsubscript{n}};
% line between server and browser
- \draw [dotted] ([xshift=-5em,yshift=-.8em]C1.south west) node[left,above]{browser} node[left,below]{server(s)} -- ([xshift=5em,yshift=-.8em]CN.south east);
+ \draw [dotted] ([xshift=-5em,yshift=-.8em]C1.south west) node[left,above]{browser} node[left,below]{server} -- ([xshift=5em,yshift=-.8em]CN.south east);
\node[task,inner sep=-4.5pt,below=of C1,fill=white,xshift=6.5em,yshift=-4.5em] (Tn) {Task\textsubscript{n}};
\node[task,inner sep=-4.5pt,below=of C1,fill=white,xshift=5em,yshift=-3.0em] (Td) {\ldots};
\node[fit={(T1)(Sn)},draw] (TS) {};
% line between client and server
- \draw [dotted] ([xshift=-5em,yshift=-11em]C1.south west) node[left,above]{server(s)} node[left,below]{device(s)} -- ([xshift=5em,yshift=-11em]CN.south east);
+ \draw [dotted] ([xshift=-5em,yshift=-11em]C1.south west) node[left,above]{server} node[left,below]{device} -- ([xshift=5em,yshift=-11em]CN.south east);
% device 1
\node[task,text width=1.5em,inner sep=-4.5pt,node distance=12em,below=of C1,double copy shadow={shadow xshift=.4em,shadow yshift=-.4em},fill=white] (D1T1) {};
The tierless implementations use just two conceptually-similar \glspl{DSL} embedded in the same host language, and a single paradigm (\cref{table_t4t:languages,table_t4t:paradigms}). In contrast, the tiers in \gls{PRS} and \gls{PWS} use six or more very different languages, and both imperative and declarative paradigms. Multiple languages are commonly used in other typical software systems like web stacks, e.g.\ a recent survey of open source projects reveals that on average at least five different languages are used \citep{mayer2015empirical}. Interoperating components in multiple languages and paradigms raises a plethora of issues.
-Interoperation \emph{increases the cognitive load on the developer} who must simultaneously think in multiple languages and paradigms. This is commonly known as semantic friction or impedance mismatch \citep{ireland2009classification}. A simple illustration of this is that the tiered \gls{PRS} source code comprises some 38 source and configuration files, whereas the tierless \gls{CRS} requires just 3 files (\cref{table_t4t:multi}). The source could be structured as a single file, but to separate concerns is structured into three modules, one each for \glspl{SDS}, types, and control logic \citep{wang_maintaining_2018}.
+Interoperation \emph{increases the cognitive load on the developer} who must simultaneously think in multiple languages and paradigms. This is commonly known as semantic friction or impedance mismatch \citep{ireland_classification_2009}. A simple illustration of this is that the tiered \gls{PRS} source code comprises some 38 source and configuration files, whereas the tierless \gls{CRS} requires just 3 files (\cref{table_t4t:multi}). The source could be structured as a single file, but to separate concerns is structured into three modules, one each for \glspl{SDS}, types, and control logic \citep{wang_maintaining_2018}.
The developer must \emph{correctly interoperate the components}, e.g.\ adhere to the \gls{API} or communication protocols between components. The interoperation often entails additional programming tasks like marshalling or demarshalling data between components. For example, in the tiered \gls{PRS} and \gls{PWS} architectures, \gls{JSON} is used to serialise and deserialise data strings from the \gls{PYTHON} collector component before storing the data in the Redis database (\cref{lst_t4t:json}).
%e.g.\ to marshall and demarshall data between components.
% Phil: so widely known that a citation is unnecessary \citep{madsen1990strong}.
That said, many distributed system components written in languages that primarily use static typing, like \gls{HASKELL} and Scala, use some dynamic typing, e.g.\ to ensure that the data arriving in a message has the anticipated type \citep{epstein2011towards,gupta2012akka}.
-In a typical tiered multi-language \gls{IOT} system the developer must integrate software in different languages with very different type systems, and potentially executing on different hardware. The challenges of maintaining type safety have long been recognised as a major component of the semantic friction in multi-language systems, e.g.\ \citep{ireland2009classification}.
+In a typical tiered multi-language \gls{IOT} system the developer must integrate software in different languages with very different type systems, and potentially executing on different hardware. The challenges of maintaining type safety have long been recognised as a major component of the semantic friction in multi-language systems, e.g.\ \citep{ireland_classification_2009}.
Even if the different languages used in two components are both strongly typed, they may attribute, often quite subtly, different types to a value. Such type errors can lead to runtime errors, or the application silently reporting erroneous data. Such errors can be hard to find. Automatic detection of such errors is sometimes possible, but requires an addition tool like Jinn \citep{Jinn,Furr2005}.
%Such errors can be hard to debug, partly because there is very limited tool support for detecting them