Context Navigation


Changeset 32


Ignore:
Timestamp:
Nov 23, 2007, 3:46:00 PM (18 years ago)
Author:
neil.c.c.brown
Message:

Fiddled with the generic pattern matching slides

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/trunk/200711-tock-seminars/200711-tock-slides.tex

    r31 r32
    547547\frametitle{Generic pattern-matching}
    548548Built our own pattern-matching library using \lstinline|Data.Generics|
    549(追記) \lstset{emph={Constr}} (追記ここまで)
    549550\begin{lstlisting}
    550551type Pattern =
    553554 | Match Constr [Pattern]
    554555\end{lstlisting}
    556(追記) \lstset{emph={}} (追記ここまで)
    555557All \lstinline|Named| items with the same name must match
    556558\end{frame}
    564566\frametitle{Building a pattern: return "x";}
    565567\includegraphics[width=100mm]{Tock-Pattern-Alt.png}
    566(削除) \end{frame} (削除ここまで)
    567(削除) (削除ここまで)
    568(削除) \begin{frame}[fragile] (削除ここまで)
    569(削除) \frametitle{Generic pattern matching} (削除ここまで)
    570(削除) %FIXME: Bits of the code on the next three slides are coloured (削除ここまで)
    571(削除) \begin{lstlisting} (削除ここまで)
    572(削除) (If (削除ここまで)
    573(削除) (Pos 0) (削除ここまで)
    574(削除) (Expr (Pos 4) (JustVar "a")) (削除ここまで)
    575(削除) (Block (Pos 7) [])) (削除ここまで)
    576(削除) (削除ここまで)
    577(削除) assertPatternMatch "If Test 0" (削除ここまで)
    578(削除) (mIf (削除ここまで)
    579(削除) Don'tCare (削除ここまで)
    580(削除) (mExpr Don'tCare (JustVar "a")) (削除ここまで)
    581(削除) (mBlock Don'tCare ([] :: [Statement]))) (削除ここまで)
    582(削除) (parse "if (a) { }") (削除ここまで)
    583(削除) (削除ここまで)
    584(削除) mExpr :: (Data a0, Data a1) => a0 -> a1 -> Pattern (削除ここまで)
    585(削除) \end{lstlisting} (削除ここまで)
    586(削除) %FIXME: Show the helpful output from a failed match? (削除ここまで)
    587(削除) %FIXME: Point out mixing of pattern and normal data here (削除ここまで)
    588568\end{frame}
    589569
    599579 testOutput
    600580
    581(追記) mBlock = tag2 Block (追記ここまで)
    582(追記) \end{lstlisting} (追記ここまで)
    583(追記) %FIXME: Point out that singleAssign' can be reused between tests (追記ここまで)
    584(追記) \end{frame} (追記ここまで)
    585(追記) (追記ここまで)
    586(追記) \begin{frame}[fragile] (追記ここまで)
    587(追記) \frametitle{Generic pattern matching} (追記ここまで)
    588(追記) \begin{lstlisting}[escapechar=\%] (追記ここまで)
    601589singleAssign' lhv rhv = mAssign Don'tCare
    602590 (mVarList Don'tCare [lhv])
    603591 (mExprList Don'tCare [mJustVar rhv])
    604\end{lstlisting}
    605%FIXME: Point out that singleAssign' can be reused between tests
    592
    593tag2 con x0 x1 = Match (toConstr con) [checkPatt x0, checkPatt x1]
    594
    595checkPatt :: Typeable a => a -> Pattern
    596checkPatt x = if x %\textit{has type Pattern}% then cast x else makePatt x
    597\end{lstlisting}
    598\end{frame}
    599
    600%For convenience, show these diagrams again (not really content!)
    601\begin{frame}[fragile]
    602\frametitle{Masking a pattern}
    603\includegraphics[width=100mm]{Tock-Pattern.png}
    604\end{frame}
    605
    606\begin{frame}[fragile]
    607\frametitle{Masking a pattern}
    608\includegraphics[width=100mm]{Tock-Pattern-Alt.png}
    609\end{frame}
    610
    611\begin{frame}[fragile]
    612\frametitle{Generic pattern matching}
    613\begin{lstlisting}
    614(If
    615 (Pos 0)
    616 (Expr (Pos 4) (JustVar "a"))
    617 (Block (Pos 7) []))
    618
    619assertPatternMatch "If Test 0"
    620 (stopCaring (Pos 999))
    621 (If
    622 (Pos 999)
    623 (Expr (Pos 999) (JustVar "a"))
    624 (Block (Pos 999) []))
    625 (parse "if (a) { }")
    626\end{lstlisting}
    627%FIXME: Show the helpful output from a failed match?
    628%FIXME: Point out mixing of pattern and normal data here
    606629\end{frame}
    607630
Note: See TracChangeset for help on using the changeset viewer.

AltStyle によって変換されたページ (->オリジナル) /