fix acronym typo
[msc-thesis1617.git] / methods.top.tex
1 \section{iTasks}
2 \gls{TOP} is a recent programming paradigm implemented as
3 \gls{iTasks}\cite{achten_introduction_2015} in the pure lazy functional
4 language \gls{Clean}\cite{brus_cleanlanguage_1987}. \gls{iTasks} is a
5 \gls{EDSL} to model workflow tasks in the broadest sense. A \CI{Task} is just
6 a function that, given some state, returns the observable \CI{TaskValue}. The
7 \CI{TaskValue} of a \CI{Task} can have different states. Not all state
8 transitions are possible as shown in Figure~\ref{fig:taskvalue}. Once a value
9 is stable it can never become unstable again. Stability is often reached
10 by pressing a confirmation button. \glspl{Task} yielding a constant value are
11 immediately stable.
12
13 A simple \gls{iTasks} example illustrating the route to stability of a
14 \gls{Task} in which the user has to enter a full name is shown in
15 Listing~\ref{lst:taskex}. The code is accompanied by screenshots showing the
16 user interface in Figure~\ref{fig:taskex1},~\ref{fig:taskex2}
17 and~\ref{fig:taskex3}. The \CI{TaskValue} of the \gls{Task} is in the first
18 image in the \CI{NoValue} state, the second image does not have all the fields
19 filled in and therefore the \CI{TaskValue} remains \CI{Unstable}. In the third
20 image all fields are entered and the \CI{TaskValue} transitions to the
21 \CI{Unstable} state. When the user presses \emph{Continue} the value becomes
22 \CI{Stable} and can not be changed any further.
23
24 \begin{figure}[H]
25 \centering
26 \includegraphics[width=.5\linewidth]{fig-taskvalue}
27 \caption{The states of a \CI{TaskValue}}\label{fig:taskvalue}
28 \end{figure}
29
30 \begin{lstlisting}[language=Clean,label={lst:taskex},%
31 caption={An example \gls{Task} for entering a name}]
32 :: Name = { firstname :: String
33 , lastname :: String
34 }
35
36 derive class iTask Name
37
38 enterInformation :: String [EnterOption m] -> (Task m) | iTask m
39
40 enterName :: Task Name
41 enterName = enterInformation "Enter your name" []
42 \end{lstlisting}
43
44 \begin{figure}[H]
45 \begin{subfigure}{.25\textwidth}
46 \centering
47 \includegraphics[width=.9\linewidth]{taskex1}
48 \caption{Initial interface}\label{fig:taskex1}
49 \end{subfigure}
50 \begin{subfigure}{.25\textwidth}
51 \centering
52 \includegraphics[width=.9\linewidth]{taskex2}
53 \caption{Incomplete entrance}\label{fig:taskex2}
54 \end{subfigure}
55 \begin{subfigure}{.25\textwidth}
56 \centering
57 \includegraphics[width=.9\linewidth]{taskex3}
58 \caption{Complete entry}\label{fig:taskex3}
59 \end{subfigure}
60 \caption{Example of a generated user interface}
61 \end{figure}
62
63 For a type to be suitable it must have instances for a collection of generic
64 functions that are captured in the class \CI{iTask}. Basic types have
65 specialization instances for these functions and show an according interface.
66 Generated interfaces can be modified with decoration operators.
67
68 \section{Combinators}
69 \Glspl{Task} can be combined using so called \gls{Task}-combinators.
70 Combinators describe relations between \glspl{Task}. \Glspl{Task} can be
71 combined in parallel, sequenced and their result values can be converted to
72 \glspl{SDS}. Moreover, a very important combinator is the step combinator that
73 starts a new task according to the \CI{TaskValue}. The type signatures of the
74 basic combinators are shown in Listing~\ref{lst:combinators}.
75
76 \begin{itemize}
77 \item Step:
78
79 The step combinator is used to start \glspl{Task} when a predicate on
80 the \CI{TaskValue} holds or an action has been taken place. The bind
81 operator can be written as a step combinator.
82 \begin{lstlisting}[language=Clean]
83 (>>=) infixl 1 :: (Task a) (a -> (Task b)) -> (Task b) | iTask a & iTask b
84 (>>=) ta f = ta >>* [OnAction "Continue" onValue, OnValue onStable]
85 where
86 onValue (Value a _) = Just (f a)
87 onValue _ = Nothing
88
89 onStable (Value a True) = Just (f a)
90 onStable _ = Nothing
91 \end{lstlisting}
92 \item Parallel:
93
94 The parallel combinator allows for concurrent \glspl{Task}. The
95 \glspl{Task} combined with these operators will appear at the same time
96 in the web browser of the user and the results are combined as the type
97 dictates.
98 \end{itemize}
99
100 \begin{lstlisting}[language=Clean,%
101 caption={\Gls{Task}-combinators},label={lst:combinators}]
102 //Step combinator
103 (>>*) infixl 1 :: (Task a) [TaskCont a (Task b)] -> Task b | iTask a & iTask b
104 (>>=) infixl 1 :: (Task a) (a -> Task b) -> Task b | iTask a & iTask b
105 :: TaskCont a b
106 = OnValue ((TaskValue a) -> Maybe b)
107 | OnAction Action ((TaskValue a) -> Maybe b)
108 | E.e: OnException (e -> b) & iTask e
109 | OnAllExceptions (String -> b)
110 :: Action = Action String
111
112 //Parallel combinators
113 (-||-) infixr 3 :: (Task a) (Task a) -> Task a | iTask a
114 (||-) infixr 3 :: (Task a) (Task b) -> Task b | iTask a & iTask b
115 (-||) infixl 3 :: (Task a) (Task b) -> Task a | iTask a & iTask b
116 (-&&-) infixr 4 :: (Task a) (Task b) -> Task (a,b) | iTask a & iTask b
117 \end{lstlisting}
118
119 \section{\acrlongpl{SDS}}
120 \Glspl{SDS} are an abstraction over resources that are available in the world
121 or in the \gls{iTasks} system. The shared data can be a file on disk, it can be
122 the time, a random integer or just some data stored in memory. The actual
123 \gls{SDS} is just a record containing functions on how to read and write the
124 source. In these functions the \CI{*World} is available and therefore it can
125 interact with the outside world. The \CI{*IWorld} is also available and
126 therefore the functions can also access other shares, possibly combining them.
127
128 The basic operations for \glspl{SDS} are get, set and update. The signatures
129 for these functions are shown in Listing~\ref{lst:shares}. All of the
130 operations are atomic in the sense that during reading no other tasks are
131 executed.
132
133 \begin{lstlisting}[%
134 language=Clean,label={lst:shares},caption={\Gls{SDS} functions}]
135 get :: (ReadWriteShared r w) -> Task r | iTask r
136 set :: w (ReadWriteShared r w) -> Task w | iTask w
137 upd :: (r -> w) (ReadWriteShared r w) -> Task w | iTask r & iTask w
138
139 \end{lstlisting}