Changeset 16
- 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 405 405 (assertEqual "Test 0") "foo_bar" (cStyleNames "foo.bar") 406 406 407 (追記) -- QuickCheck example: (追記ここまで) 408 (追記) (追記ここまで) 407 409 -- Generates a list of random numbers that sums to the given total: 408 410 randList :: Int -> RandomMonad [Int] … … 414 416 \end{lstlisting} 415 417 \end{frame} 418 (追記) %TODO consider replacing the above QuickCheck example with a simpler one (追記ここまで) 416 419 417 420 \begin{frame} 418 421 \frametitle{Writing tests} 419 422 \begin{itemize} 420 \item (削除) T (削除ここまで)esting the complex output of a function423 \item (追記) When t (追記ここまで)esting the complex output of a function 421 424 \begin{itemize} 422 425 \item May want to ignore some of the output because it's … … 443 446 If 444 447 (Pos 0) 445 (Expr (Pos 4) 446 (JustVar "a")) 447 (Block (Pos 7) 448 []) 448 (Expr (Pos 4) (JustVar "a")) 449 (Block (Pos 7) [ ]) 449 450 \end{lstlisting} 450 451 \end{frame} … … 454 455 \begin{lstlisting} 455 456 (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) [ (追記ここまで)])) 457 458 (parse "if (a) { }") 458 459 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 (削除) (削除ここまで)461 460 (assertBool "If Test 0") (checkIfTest0 (parse "if (a) { }")) 462 463 checkIfTest0 (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 469 469 \end{lstlisting} 470 470 \end{frame} … … 477 477 t := y 478 478 y := x 479 x := t 480 \end{verbatim} 479 x := t\end{verbatim} 481 480 \begin{lstlisting} 482 481 Assign p0 (VarList p0 ["x", "y"]) (ExprList p0 [JustVar "x", JustVar "y"]) 483 482 484 Block (削除) (Pos 5) (削除ここまで)483 Block (追記) p0 (追記ここまで) 485 484 [ Assign p0 (VarList p0 ["t"]) (ExprList p0 [JustVar "y"]) 486 485 , Assign p0 (VarList p0 ["y"]) (ExprList p0 [JustVar "x"]) … … 501 500 , singleAssign "x" "t" 502 501 ]) 503 504 (transformAssign 505 (Assign (Pos 5) (VarList (Pos 0) ["x", "y"]) 506 (ExprList (Pos 8) [JustVar "x", JustVar "y"]))) 502 testOutput 507 503 508 504 singleAssign lhv rhv … … 515 511 \begin{lstlisting} 516 512 assertBool "tempAssignTest 0" 517 (checktempAssignTest0 518 (transformAssign 519 (Assign p0 (VarList p0 ["x","y"]) 520 (ExprList p0 [JustVar "x", JustVar "y"])))) 513 (checktempAssignTest0 testOutput) 521 514 522 515 checktempAssignTest0 (Block _ … … 563 556 \begin{itemize} 564 557 \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} (削除ここまで)569 558 \end{itemize} 570 559 \begin{lstlisting} … … 596 585 (Pos 0) 597 586 (Expr (Pos 4) (JustVar "a")) 598 (Block (Pos 7) [ (削除) (削除ここまで)]))587 (Block (Pos 7) [(追記) (追記ここまで)])) 599 588 600 589 assertPatternMatch "If Test 0" 601 ( (削除) tag3 (削除ここまで)If590 ((追記) m (追記ここまで)If 602 591 DC 603 ( (削除) tag2 (削除ここまで)Expr DC (JustVar "a"))604 ( (削除) tag2 Block DC ([ (削除ここまで)] :: [Statement])))592 ((追記) m (追記ここまで)Expr DC (JustVar "a")) 593 ((追記) mBlock DC ([ (追記ここまで)] :: [Statement]))) 605 594 (parse "if (a) { }") 595 (追記) (追記ここまで) 596 (追記) mExpr :: (Data a0, Data a1) => a0 -> a1 -> Pattern (追記ここまで) 606 597 \end{lstlisting} 607 598 \end{frame} … … 611 602 \begin{lstlisting} 612 603 (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 621 singleAssign' 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 632 605 [ singleAssign' ("tempVar" @@ DC) "y" 633 606 , singleAssign' "y" "x" 634 607 , singleAssign' "x" ("tempVar" @@ DC) 635 608 ]) 636 (transformAssign (Assign (Pos 5) (VarList (Pos 0) ["x", "y"]) 637 (ExprList (Pos 8) [JustVar "x", JustVar "y"])) 638 639 singleAssign' lhv rhv = Assign_ DC 640 (VarList_ DC [lhv]) 641 (ExprList_ DC [JustVar_ rhv]) 642 643 Block_ = tag2 Block 644 Assign_ = tag3 Assign 645 ... 609 testOutput 610 611 singleAssign' lhv rhv = mAssign DC 612 (mVarList DC [lhv]) 613 (mExprList DC [mJustVar rhv]) 646 614 \end{lstlisting} 647 615 \end{frame}
Note:
See TracChangeset
for help on using the changeset viewer.