Merge branch 'master' of git.martlubbers.net:msc-thesis1617
[msc-thesis1617.git] / mtask.io.tex
1 Values can be assigned to all expressions that have an \CI{Upd} role. Examples
2 of such expressions are \glspl{SDS} and \gls{GPIO} pins. Moreover, class
3 extensions can be created for specific peripherals such as built-in
4 \glspl{LED}. The classes facilitating this are shown in
5 Listing~\ref{lst:sdsio}. In this way the assignment is the same for every
6 assignable entity.
7
8 \begin{lstlisting}[language=Clean,%
9 label={lst:sdsio},caption={Input/Output classes}]
10 :: DigitalPin = D0 | D1 | D2 | D3 | D4 | D5 |D6 | D7 | D8 | D9 | D10 | D11 | D12 | D13
11 :: AnalogPin = A0 | A1 | A2 | A3 | A4 | A5
12 :: UserLED = LED1 | LED2 | LED3
13
14 class dIO v where dIO :: DigitalPin -> v Bool Upd
15 class aIO v where aIO :: AnalogPin -> v Int Upd
16 class analogRead v where
17 analogRead :: AnalogPin -> v Int Expr
18 analogWrite :: AnalogPin (v Int p) -> v Int Expr
19 class digitalRead v where
20 digitalRead :: DigitalPin -> v Bin Expr
21 digitalWrite :: DigitalPin (v Bool p) -> v Int Expr
22
23 :: UserLED = LED1 | LED2 | LED3
24 class userLed v where
25 ledOn :: (v UserLED q) -> (v () Stmt)
26 ledOff :: (v UserLED q) -> (v () Stmt)
27
28 class assign v where
29 (=.) infixr 2 :: (v t Upd) (v t p) -> v t Expr | ...
30 \end{lstlisting}
31
32 One way of storing data in \gls{mTask}-\glspl{Task} is using \glspl{SDS}.
33 \glspl{SDS} serve as global variables in \gls{mTask} and maintain their value
34 across executions. \glspl{SDS} can be used by multiple \glspl{Task} and can be
35 used to share data. The classes associated with \glspl{SDS} are listed in
36 Listing~\ref{lst:sdsclass}. The \CI{Main} type is introduced to box an
37 \gls{mTask} and make it recognizable by the type system by separating programs
38 and decorations such as \glspl{SDS}. The type signature is complex and uses
39 infix type constructors and therefore, an implementation example is also given.
40
41 \begin{lstlisting}[language=Clean,%
42 label={lst:sdsclass},caption={\glspl{SDS} in \gls{mTask}}]
43 :: In a b = In infix 0 a b
44 :: Main a = {main :: a}
45
46 class sds v where
47 sds :: ((v t Upd) -> In t (Main (v c s))) -> (Main (v c s)) | ...
48
49 sdsExample :: Main (v Int Stmt)
50 sdsExample = sds \x.0 In
51 {main= x =. x +. lit 42 }
52 \end{lstlisting}