From: pimjager Date: Thu, 17 Mar 2016 11:18:17 +0000 (+0100) Subject: Added some stuff to slides X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=3d845cb7fe8ccdfd9799aae41acf8b81ed36a970;p=cc1516.git Added some stuff to slides --- diff --git a/deliverables/p1/p1.tex b/deliverables/p1/p1.tex index 11b4699..27c30d1 100644 --- a/deliverables/p1/p1.tex +++ b/deliverables/p1/p1.tex @@ -38,6 +38,10 @@ :: Error = PositionalError Int Int String | Error String :: Parser a b = Parser ([a] -> (Either Error b, [a])) \end{CleanCode} + \pause + \item Result is either Error or \texttt{b}, not a \texttt{[b]} as + described Hutton \& Meijer \footnote{G. Hutton and E. Meijer. + Monadic parser combinators. 1996.} \pause \item Matches longest left-most parser \pause @@ -48,24 +52,74 @@ \begin{frame}[fragile] \frametitle{\textsc{YARD} Combinators} - \begin{CleanCode} -instance Functor (Parser a) -instance Applicative (Parser a) -instance Monad (Parser a) -instance Alternative (Parser a) - -runParser :: (Parser a b) [a] -> (Either Error b, [a]) -() :: (Parser a b) Error -> Parser a b + \framesubtitle{Designed to be minimal, just 14 parsers/combinators} + YARD is designed to be minimal and defines just 14 primitives: + \begin{columns}[t] + \begin{column}{0.5\textwidth} + \begin{CleanCode} +top :: Parser a a +peek :: Parser a a fail :: Parser a b +eof :: Parser a Void +(until) :: (Parser a b) + (Parser a c) + -> Parser a [b] +satisfy :: (a -> Bool) + -> Parser a a +check :: (a -> Bool) + -> Parser a a +item :: a -> Parser a a +list :: [a] -> Parser a [a] + \end{CleanCode} + \end{column} + \begin{column}{0.5\textwidth} + \begin{CleanCode} +(>>=) :: (Parser a b) + (b -> Parser a c) + -> Parser a c +(<|>) :: (Parser a b) + (Parser a b) + -> Parser a b +some :: (Parser a b) + -> Parser a [b] +many :: (Parser a b) + -> Parser a [b] +optional :: (Parser a b) + -> Parser a (Maybe b) + \end{CleanCode} + \end{column} + \end{columns} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\textsc{YARD} Combinators} + \framesubtitle{Designed to be minimal, just \textbf{7} parsers/combinators} + Actually, scrap that, just \textbf{7} primitives: + \begin{columns}[t] + \begin{column}{0.5\textwidth} + \begin{CleanCode} top :: Parser a a peek :: Parser a a -satisfy :: (a -> Bool) -> Parser a a -check :: (a -> Bool) -> Parser a a -(until) infix 2 :: (Parser a b) (Parser a c) -> Parser a [b] -item :: a -> Parser a a | Eq a -list :: [a] -> Parser a [a] | Eq a +fail :: Parser a b eof :: Parser a Void - \end{CleanCode} + \end{CleanCode} + \end{column} + \begin{column}{0.5\textwidth} + \begin{CleanCode} +(>>=) :: (Parser a b) + (b -> Parser a c) + -> Parser a c +(<|>) :: (Parser a b) + (Parser a b) + -> Parser a b + \end{CleanCode} + \end{column} + \end{columns} + All others can be (and are) derived from these. e.g. + \begin{lstlisting} +satisfy :: (a -> Bool) -> Parser a a +satisfy f = top >>= \c -> if (f c) (return c) fail + \end{lstlisting} \end{frame} \section{Design choices}