Context Navigation


Changeset 16


Ignore:
Timestamp:
Nov 23, 2007, 12:13:25 AM (18 years ago)
Author:
neil.c.c.brown
Message:

Tried to tidy up, simplify and chop the code for the generic pattern matching stuff

File:
1 edited

Legend:

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

    r15 r16
    405405(assertEqual "Test 0") "foo_bar" (cStyleNames "foo.bar")
    406406
    407(追記) -- QuickCheck example: (追記ここまで)
    408(追記) (追記ここまで)
    407409-- Generates a list of random numbers that sums to the given total:
    408410randList :: Int -> RandomMonad [Int]
    414416\end{lstlisting}
    415417\end{frame}
    418(追記) %TODO consider replacing the above QuickCheck example with a simpler one (追記ここまで)
    416419
    417420\begin{frame}
    418421\frametitle{Writing tests}
    419422\begin{itemize}
    420 \item (削除) T (削除ここまで)esting the complex output of a function
    423 \item (追記) When t (追記ここまで)esting the complex output of a function
    421424 \begin{itemize}
    422425 \item May want to ignore some of the output because it's
    443446If
    444447 (Pos 0)
    445 (Expr (Pos 4)
    446 (JustVar "a"))
    447 (Block (Pos 7)
    448 [])
    448 (Expr (Pos 4) (JustVar "a"))
    449 (Block (Pos 7) [ ])
    449450\end{lstlisting}
    450451\end{frame}
    454455\begin{lstlisting}
    455456(assertEqual "If Test 0")
    456 (If (Pos 0) (Expr (Pos 4) (JustVar "a")) (Block (Pos (削除) 8) [ (削除ここまで)]))
    457 (If (Pos 0) (Expr (Pos 4) (JustVar "a")) (Block (Pos (追記) 7) [ (追記ここまで)]))
    457458 (parse "if (a) { }")
    458459
    459(削除) "If Test 0 failed; expected: (If (Pos 0) (Expr (Pos 4) (JustVar "a")) (Block (Pos 8) [])) but got (If (Pos 0) (Expr (Pos 4) (JustVar "a")) (Block (Pos 7) []))" (削除ここまで)
    460(削除) (削除ここまで)
    461460(assertBool "If Test 0") (checkIfTest0 (parse "if (a) { }"))
    462
    463checkIfTest0 (If _ (Expr _ (JustVar "a"))
    464 (Block _ [ NullStatement ])) = True
    465 checkIfTest0 _ = False
    466
    467"If Test 0 failed
    468 got (If (Pos 0) (Expr (Pos 4) (JustVar "a")) (Block (Pos 7) []))"
    461 where
    462 checkIfTest0
    463 (If _
    464 (Expr _ (JustVar "a"))
    465 (Block _ [ ])
    466 ) = True
    467 checkIfTest0 _ = False
    468
    469469\end{lstlisting}
    470470\end{frame}
    477477t := y
    478478y := x
    479x := t
    480\end{verbatim}
    479x := t\end{verbatim}
    481480\begin{lstlisting}
    482481Assign p0 (VarList p0 ["x", "y"]) (ExprList p0 [JustVar "x", JustVar "y"])
    483482
    484Block (削除) (Pos 5) (削除ここまで)
    483Block (追記) p0 (追記ここまで)
    485484 [ Assign p0 (VarList p0 ["t"]) (ExprList p0 [JustVar "y"])
    486485 , Assign p0 (VarList p0 ["y"]) (ExprList p0 [JustVar "x"])
    501500 , singleAssign "x" "t"
    502501 ])
    503
    504 (transformAssign
    505 (Assign (Pos 5) (VarList (Pos 0) ["x", "y"])
    506 (ExprList (Pos 8) [JustVar "x", JustVar "y"])))
    502 testOutput
    507503
    508504singleAssign lhv rhv
    515511\begin{lstlisting}
    516512assertBool "tempAssignTest 0"
    517 (checktempAssignTest0
    518 (transformAssign
    519 (Assign p0 (VarList p0 ["x","y"])
    520 (ExprList p0 [JustVar "x", JustVar "y"]))))
    513 (checktempAssignTest0 testOutput)
    521514
    522515checktempAssignTest0 (Block _
    563556\begin{itemize}
    564557 \item Built on |Data.Generics|
    565(削除) \item Can match any Haskell data type by introspection (削除ここまで)
    566(削除) \begin{itemize} (削除ここまで)
    567(削除) \item You just have to know what the type constructor is (削除ここまで)
    568(削除) \end{itemize} (削除ここまで)
    569558\end{itemize}
    570559\begin{lstlisting}
    596585 (Pos 0)
    597586 (Expr (Pos 4) (JustVar "a"))
    598 (Block (Pos 7) [(削除) (削除ここまで)]))
    587 (Block (Pos 7) [(追記) (追記ここまで)]))
    599588
    600589assertPatternMatch "If Test 0"
    601 ((削除) tag3 (削除ここまで)If
    590 ((追記) m (追記ここまで)If
    602591 DC
    603 ((削除) tag2 (削除ここまで)Expr DC (JustVar "a"))
    604 ((削除) tag2 Block DC ([ (削除ここまで)] :: [Statement])))
    592 ((追記) m (追記ここまで)Expr DC (JustVar "a"))
    593 ((追記) mBlock DC ([ (追記ここまで)] :: [Statement])))
    605594 (parse "if (a) { }")
    595(追記) (追記ここまで)
    596(追記) mExpr :: (Data a0, Data a1) => a0 -> a1 -> Pattern (追記ここまで)
    606597\end{lstlisting}
    607598\end{frame}
    611602\begin{lstlisting}
    612603(assertPatternMatch "tempAssignTest 0")
    613 (tag2 Block DC
    614 [ singleAssign' (Named "tempVar" DC) "y"
    615 , singleAssign' "y" "x"
    616 , singleAssign' "x" (Named "tempVar" DC)
    617 ])
    618 (transformAssign (Assign (Pos 5) (VarList (Pos 0) ["x", "y"])
    619 (ExprList (Pos 8) [JustVar "x", JustVar "y"]))
    620
    621singleAssign' lhv rhv = tag3 Assign DC
    622 (tag2 VarList DC [lhv])
    623 (tag2 ExprList DC [tag1 JustVar rhv])
    624\end{lstlisting}
    625\end{frame}
    626
    627\begin{frame}[fragile]
    628\frametitle{Generic pattern matching}
    629\begin{lstlisting}
    630(assertPatternMatch "tempAssignTest 0")
    631 (Block_ DC
    604 (mBlock DC
    632605 [ singleAssign' ("tempVar" @@ DC) "y"
    633606 , singleAssign' "y" "x"
    634607 , singleAssign' "x" ("tempVar" @@ DC)
    635608 ])
    636 (transformAssign (Assign (Pos 5) (VarList (Pos 0) ["x", "y"])
    637 (ExprList (Pos 8) [JustVar "x", JustVar "y"]))
    638
    639singleAssign' lhv rhv = Assign_ DC
    640 (VarList_ DC [lhv])
    641 (ExprList_ DC [JustVar_ rhv])
    642
    643Block_ = tag2 Block
    644Assign_ = tag3 Assign
    645...
    609 testOutput
    610
    611singleAssign' lhv rhv = mAssign DC
    612 (mVarList DC [lhv])
    613 (mExprList DC [mJustVar rhv])
    646614\end{lstlisting}
    647615\end{frame}
Note: See TracChangeset for help on using the changeset viewer.

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