\item Rewrite the following equations in reverse Polish notation and solve by hand:
\begin{enumerate}[label=(\roman*)]
\item$(9-3) + \log (8)$
\item$(10/4) - \sqrt{ 4 }$
\end{enumerate}
\item Use the algorithm from the lecture to check by hand whether \texttt{[]([({})[]])} and \texttt{[][()){}]} are valid bracket expressions.
\end{enumerate}
\section*{Aufgabe 2: Module}
\begin{enumerate}
\item Create a module \lstinline{Queue} that exports the algebraic data type \lstinline{Queue} and the functions \lstinline{isEmpty}, \lstinline{dequeue} and \lstinline{enqueue}. \par
The functions in question are attached below, otherwise the example from the live code of the lecture (\lstinline{FQueue}) should be used.\par
Add the functions
\begin{enumerate}[label=(\roman*)]
\item\lstinline{hasElem :: Queuelike a => b -> a b -> Bool}(checks whether the passed value is contained in the \lstinline{Queue})
\item\lstinline{count :: Queuelike a => b -> a b -> Int}(counts how often the passed value is contained in the \lstinline{queue})
\end{enumerate}
and export them.
\begin{lstlisting}[language=Haskell]
-- Type class for Queues
class Queuelike s where
enqueue :: a -> s a -> s a
dequeue :: s a -> Maybe (a, s a)
isEmpty :: s a -> Bool
data Queue a = Q [a][a] deriving Show
--(Q inp out) the first list is used for inserting elements, the second one for removing.
instance Queuelike Queue where
enqueue x (Q inp out )= Q (x:inp) out
dequeue (Q [][])= Nothing
dequeue (Q inp [])= dequeue (Q [](reverse inp))
dequeue (Q inp (x:out))= Just (x, Q inp out)
isEmpty (Q [][])= True
isEmpty _= False
\end{lstlisting}
\newpage
\item Import the module into a new Haskell file and write the following functions that simulate a checkout queue in a shop.
In the queue, you queue people with shopping trolleys. Each shopping trolley contains different products with assigned prices.
\begin{enumerate}[label=(\roman*)]
\item Write suitable type synonyms or algebraic data types that represent a shopping trolley and the queue of shopping trolleys.
\item Write a function \lstinline{anstellen} in which a shopping trolley is added to the checkout queue.
\item Write a function \lstinline{cash} that determines the total price of the goods for the shopping trolley that was queued first.
The return of \lstinline{kassieren} should be a tuple of the total price and the new checkout queue.
\end{enumerate}
\end{enumerate}
% /////////////////////// END DOKUMENT /////////////////////////