update
[msc-thesis1617.git] / mtask.control.tex
1 Looping of \glspl{Task} happens because \glspl{Task} are executed after waiting
2 a specified amount of time or when they are launched by another \gls{Task} or
3 even themselves. Therefore there is no need for loop control flow functionality
4 such as \emph{while} or \emph{for} constructions. The main control flow
5 operators are the sequence operator and the \emph{if} statement. Both are shown
6 in Listing~\ref{lst:control}. The first class of \emph{If} statements describes
7 the regular \emph{if} statement. The expressions given can have any role. The
8 functional dependency on \CI{s} determines the return type of the statement.
9 The listing includes examples of implementations that illustrate this
10 dependency. A special \emph{If} statement --- only used for statements --- is
11 also added under the name \CI{IF}, of which the \CI{?} is a conditional
12 statement to execute.
13
14 The sequence operator is straightforward and its only function is to tie
15 two expressions together. The left expression is executed first, followed by
16 the right expression.
17
18 \begin{lstlisting}[%
19 label={lst:control},caption={Control flow operators}]
20 class If v q r ~s where
21 If :: (v Bool p) (v t q) (v t r) -> v t s | ...
22
23 class IF v where
24 IF :: (v Bool p) (v t q) (v s r) -> v () Stmt | ...
25 (?) infix 1 :: (v Bool p) (v t q) -> v () Stmt | ...
26
27 instance If Code Stmt Stmt Stmt
28 instance If Code e Stmt Stmt
29 instance If Code Stmt e Stmt
30 instance If Code x y Expr
31
32 class seq v where
33 (:.) infixr 0 :: (v t p) (v u q) -> v u Stmt | ...
34 \end{lstlisting}