2007-06-21
■ [Chapter6] Programming with lists (4日目) 
6.2 Extended exercise: positioned pictures
今度は、 Picture に座標 (Position) の概念を加えてみましょう、という話。 Position を含む Picture を Image として再定義している。
type Position = (Int,Int)
type Image = (Picture, Position)
Exercises 6.9
Picture と Position から Image を作る makeImage 関数を定義する。
makeImage :: Picture -> Position -> Image
Exercises 6.10
指定した Position を Image に再設定する関数 changePosition 関数を定義する。
changePosition :: Image -> Position -> Image
Exercises 6.11
x軸に指定した数だけ移動させ、y軸にも指定した数だけ移動させる関数 moveImage を定義する。
moveImage :: Image -> Int -> Int -> Image
moveImage img xmov ymov = ( (fst img), ( (xmov + (fst $ snd img) ) , (ymov + (snd $ snd img) ) ) )
Exercises 6.12
Exercises 6.4 の printPicture のように、絵っぽく表示する関数 printImage を定義する。
printImage :: Image -> IO()
printImage img = putStr $ unlines $
[ "|" ++ (replicate (fst $ snd img) ' ') ++ line | line <- (fst img) ] ++
(replicate (snd $ snd img) ( "|" ++ replicate ( (fst $ snd img) + (length $ head $ fst img) ) ' ') )
++ [ ("+" ++ replicate ( (fst $ snd img) + (length $ head $ fst img) ) '-') ]
うわ。あとでもう少し整理しないと・・・。
今後の学習
残Section数 88, 残Exercise数 356
Andralyn2012/01/08 15:50Great insight! That's the answer we've been lokonig for.
hagvmaooe2012/01/09 02:09Y16YzX <a href="http://pppyvokzjahc.com/">pppyvokzjahc</a>
ttqrgxrcy2012/01/09 21:25CqKQ4q , [url=http://hgspixnethev.com/]hgspixnethev[/url], [link=http://rumxclteqvlu.com/]rumxclteqvlu[/link], http://tqeueagtggux.com/
myfrzsivhnj2012/01/14 03:46SeRADp , [url=http://gadujgwfohas.com/]gadujgwfohas[/url], [link=http://oceaosehzcrk.com/]oceaosehzcrk[/link], http://dswfycruoqgp.com/