add system overview
[msc-thesis1617.git] / top.combinators.tex
1 \Glspl{Task} can be combined using so called \gls{Task}-combinators.
2 Combinators describe relations between \glspl{Task}. There are only two basic
3 types of combinators; parallel and sequence. All other combinators are
4 derived from the basic combinators. Type signatures of simplified versions of
5 the basic combinators and their derivations are given in
6 Listing~\ref{lst:combinators}
7
8 \begin{lstlisting}[%
9 caption={\Gls{Task}-combinators},label={lst:combinators}]
10 //Step combinator
11 (>>=) infixl 1 :: (Task a) (a -> Task b) -> Task b | iTask a & iTask b
12 (>>*) infixl 1 :: (Task a) [TaskCont a (Task b)] -> Task b | iTask a & iTask b
13 :: TaskCont a b
14 = OnValue ((TaskValue a) -> Maybe b)
15 | OnAction Action ((TaskValue a) -> Maybe b)
16 | E.e: OnException (e -> b) & iTask e
17 | OnAllExceptions (String -> b)
18 :: Action = Action String
19
20 //Parallel combinators
21 (-||-) infixr 3 :: (Task a) (Task a) -> Task a | iTask a
22 (||-) infixr 3 :: (Task a) (Task b) -> Task b | iTask a & iTask b
23 (-||) infixl 3 :: (Task a) (Task b) -> Task a | iTask a & iTask b
24 (-&&-) infixr 4 :: (Task a) (Task b) -> Task (a,b) | iTask a & iTask b
25 \end{lstlisting}
26
27 \paragraph{Sequence:}
28 The implementation for the sequence combinator is called the
29 \CI{step} (\CI{>>*}). This combinator runs the left-hand \gls{Task} and
30 starts the right-hand side when a certain predicate holds. Predicates
31 can be propositions about the \CI{TaskValue}, user actions from within
32 the web browser or a thrown exception. The familiar
33 bind-combinator is an example of a sequence combinator. This combinator
34 runs the left-hand side and continues to the right-hand \gls{Task} if
35 there is an \CI{UnStable} value and the user presses continue or when
36 the value is \CI{Stable}. The combinator could have been implemented
37 as follows:
38 \begin{lstlisting}[language=Clean]
39 (>>=) infixl 1 :: (Task a) (a -> (Task b)) -> (Task b) | iTask a & iTask b
40 (>>=) ta f = ta >>* [OnAction "Continue" onValue, OnValue onStable]
41 where
42 onValue (Value a _) = Just (f a)
43 onValue _ = Nothing
44
45 onStable (Value a True) = Just (f a)
46 onStable _ = Nothing
47 \end{lstlisting}
48
49 \paragraph{Parallel:}
50 The parallel combinator allows for concurrent \glspl{Task}. The
51 \glspl{Task} combined with these operators will appear at the same time
52 in the web browser of the user and the results are combined as the type
53 dictates. All parallel combinators used are derived from the basic parallel
54 combinator that is very complex and only used internally.