X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=methods.mtask.tex;h=df05035720e5ebc7621fccd8fae2d49d8a0f5146;hb=f51f8bb08edd8fb7cd0be5ba3955ad9e27cfdbe1;hp=5bdbbb1db3f162006b9b9e7da5462820718364b5;hpb=435b0d98d22a47530f50ff82f2451e70ce2bed96;p=msc-thesis1617.git diff --git a/methods.mtask.tex b/methods.mtask.tex index 5bdbbb1..df05035 100644 --- a/methods.mtask.tex +++ b/methods.mtask.tex @@ -26,7 +26,7 @@ restriction describes updatable expressions such as \gls{GPIO} pins and \glspl{SDS}. \begin{lstlisting}[% - language=Clean,label={lst:exprhier},caption={Expression role hierarchy}] + label={lst:exprhier},caption={Expression role hierarchy}] :: Upd = Upd :: Expr = Expr :: Stmt = Stmt @@ -46,7 +46,7 @@ brevity. Moreover, the class restrictions are only shown in the first functions and omitted in subsequent funcitons. Both the boolean expression and arithmetic expression classes are shown in Listing~\ref{lst:arithbool}. -\begin{lstlisting}[language=Clean,label={lst:arithbool}, +\begin{lstlisting}[label={lst:arithbool}, caption={Basic classes for expressions}] class arith v where lit :: t -> v t Expr @@ -68,15 +68,23 @@ as \emph{while} or \emph{for} constructions. The main control flow operators are the sequence operator and the \emph{if} statement. Both are shown in Listing~\ref{lst:control}. The first class of \emph{If} statements describes the regular \emph{if} statement. The expressions given can have any role. The -functional dependency\todo{explain} on \CI{s} determines the return type of the -statement. The sequence operator is very straightforward and just ties the two -expressions together in sequence. +functional dependency on \CI{s} determines the return type of the +statement. The listing includes examples of implementations that illustrate +this dependency. + +The sequence operator is very straightforward and just ties +the two expressions together in sequence. \begin{lstlisting}[% - language=Clean,label={lst:control},caption={Control flow operators}] + label={lst:control},caption={Control flow operators}] class If v q r ~s where If :: (v Bool p) (v t q) (v t r) -> v t s | ... +instance If Code Stmt Stmt Stmt +instance If Code e Stmt Stmt +instance If Code Stmt e Stmt +instance If Code x y Expr + class seq v where (:.) infixr 0 :: (v t p) (v u q) -> v u Stmt | ... \end{lstlisting} @@ -84,12 +92,12 @@ class seq v where \section{Input/Output and class extensions} Values can be assigned to all expressions that have an \CI{Upd} role. Examples of such expressions are \glspl{SDS} and \gls{GPIO} pins. Moreover, class -extensions can be created for specific peripherals such as builtin LEDs. The -classes facilitating this are shown in Listing~\ref{lst:sdsio}. In this way the -assignment is the same for every assignable entity. +extensions can be created for specific peripherals such as builtin \glspl{LED}. +The classes facilitating this are shown in Listing~\ref{lst:sdsio}. In this way +the assignment is the same for every assignable entity. \begin{lstlisting}[% - language=Clean,label={lst:sdsio},caption={Input/Output classes}] + label={lst:sdsio},caption={Input/Output classes}] :: DigitalPin = D0 | D1 | D2 | D3 | D4 | D5 |D6 | D7 | D8 | D9 | D10 | D11 | D12 | D13 :: AnalogPin = A0 | A1 | A2 | A3 | A4 | A5 :: UserLED = LED1 | LED2 | LED3 @@ -119,7 +127,7 @@ Listing~\ref{lst:sdsclass}. The \CI{Main} type is introduced to box an \gls{mTask} and make it recognizable by the type system. \begin{lstlisting}[% - language=Clean,label={lst:sdsclass},caption={\glspl{SDS} in \gls{mTask}}] + label={lst:sdsclass},caption={\glspl{SDS} in \gls{mTask}}] :: In a b = In infix 0 a b :: Main a = {main :: a} @@ -172,11 +180,11 @@ To achieve this in the \gls{EDSL} a \gls{Task} clas are added that work in a similar fashion as the \texttt{sds} class. This class is listed in Listing~\ref{lst:taskclass}. \glspl{Task} can have an argument and always have to specify a delay or waiting time. The type signature of the \CI{mtask} is -rather arcane and therefore an example is given. The aforementioned Listing +complex and therefore an example is given. The aforementioned Listing shows a simple specification containing one task that increments a value indefinitely every one seconds. -\begin{lstlisting}[language=Clean,label={lst:taskclass},% +\begin{lstlisting}[label={lst:taskclass},% caption={The classes for defining tasks}] class mtask v a where task :: (((v delay r) a->v MTask Expr)->In (a->v u p) (Main (v t q))) -> Main (v t q) | ... @@ -189,13 +197,13 @@ Some example \glspl{mTask} using almost all of the functionality are shown in Listing~\ref{lst:exmtask}. The \glspl{mTask} shown in the example do not belong to a particular view and therefore are of the type \CI{View t r}. The \CI{blink} \gls{mTask} show the classic \gls{Arduino} \emph{Hello World!} -application that blinks a certain LED every second. The \CI{thermostat} -expression will enable a digital pin powering a cooling fan when the analog -pin representing a temperature sensor is too high. \CI{thermostat`} shows the -same expression but now using the assignment style \gls{GPIO} technique. +application that blinks a certain \gls{LED} every second. The \CI{thermostat} +expression will enable a digital pin powering a cooling fan when the analog pin +representing a temperature sensor is too high. \CI{thermostat`} shows the same +expression but now using the assignment style \gls{GPIO} technique. \begin{lstlisting}[% - language=Clean,label={lst:exmtask},caption={Some example \glspl{mTask}}] + label={lst:exmtask},caption={Some example \glspl{mTask}}] blink = task \blink=(\x. IF (x ==. lit True) (ledOn led) (ledOff led) :. blink (lit 1000) (Not x) @@ -203,7 +211,7 @@ blink = task \blink=(\x. thermostat :: Main (View () Stmt) thermostat = {main = - IF (analogRead A0 >. 50) + IF (analogRead A0 >. lit 50) ( digitalWrite D0 (lit True) ) ( digitalWrite D0 (lit False) ) } @@ -211,5 +219,5 @@ thermostat = {main = thermostat` :: Main (View () Stmt) thermostat` = let a0 = aIO A0 - d0 = dIO D0 in {main = IF (a0 >. 50) (d0 =. lit True) (d0 =. lit False) } + d0 = dIO D0 in {main = IF (a0 >. lit 50) (d0 =. lit True) (d0 =. lit False) } \end{lstlisting}