Old/sampou.org/Books_RWH_読書会

Books_RWH_読書会

Books:RWH:読書会


RWH読書会

“Real World Haskell” を読む

第15回

日時 2011-2-?(?) 13:00-18:00 場所 タイムインターメディア 2F大会議室

『第17章 Cとのインタフェース:FFI』から読み進めます。

第14回

日時 2011-1-23(日) 13:00-18:00 場所 タイムインターメディア 2F大会議室

『第16章 Parsec を使う』まで読了。

参加はこちらから。

第13回

日時 2010-12-5(日) 13:00-18:00 場所 タイムインターメディア 2F大会議室

第15章まで読了

第12回

日時 2010-08-14(土) 13:00-18:00 場所 タイムインターメディア 2F大会議室

第11回

日時 2010-07-31(土) 13:00-18:00 場所 タイムインターメディア 2F大会議室

第13章から第14章の途中まで

読書会での質問、回答、コメントのメモです。

上のメモの補足

第10回

2010-05-22

第12章の途中(12.9)から読み進めます。

第9回

2010-04-17

前日の 擬データを使った Santa Claus problem の話

第12章

第8回

2010-03-27

第10章から第11章まで読了。

第7回

2010-01-16

第9章

第6回

2009-10-31

第7章の途中から第8章まで読了。

Chaton での実況:http://practical-scheme.net/chaton/haskell-ja/a/2009/10/31#entry-4aebc797-4d367

第5回

2009-08-23

第6章と第7章の途中まで

Chaton での実況:http://practical-scheme.net/chaton/haskell-ja/a/2009/08/23

第4回

2009-07-20

第5章

第3回

2009-06-27

第3章の途中から第4章まで読了。

第2回

2009-05-17

原書p.69 練習問題

1.,2.

numOfElems :: [a] -> Int
numOfElems (_:xs) = 1 + numOfElems xs     -- right wing :)
numOfElems _      = 0

numOfElems' :: [a] -> Int
numOfElems' (_:xs) = numOfElems' xs + 1    -- left wing :)
numOfElems' _      = 0

{-
numOfElems = foldr  (\ _ l -> 1 + l) 0 
numOfElems = foldl' (\ l _ -> l + 1) 0
-}
  1. mean xs = sum xs / fromIntegral (length xs) {- – 1パス mean = uncurry (/) . foldl’ acc (0,0) where acc (s,l) x = (s+x,l+1) -}

  2. – パターンマッチを使う mkPalindrome :: [a] -> [a] mkPalindrome (x:xs) = x : (mkPalindrome xs ++ [x]) mkPalindrome _ = []

    – 以下は蛇足... – Sコンビネータを使う mkPalindrome’ = s (++) reverse s :: (a -> b -> c) -> (a -> b) -> (a -> c) s f g x = f x (g x)

    – 与えられたリストを1度だけ辿る(ように見えるだけ?) mkPalindrome’’ = uncurry ($) . foldl f (id, []) where f (g,xs) x = (g . (x:), x : xs)

    mkPalindrome’’’ xs = foldr (b -> b++[x]) xs xs

  3. palindrome :: Eq a => [a] -> Bool palindrome xs = xs == reverse xs

    – S palindrome’ = s (==) reverse

    – 1パス? palindrome’’ xs = fst $ foldr check (True,xs) xs where check x (p,y:ys) = (x == y && p,ys)

  4. import Data.Ord (comparing)

    sortByLength :: [[a]] -> [[a]] sortByLength = map snd . sortBy (comparing snd) . map (s (,) length)

7.,8.

intersperse :: a -> [[a]] -> [a]
intersperse s []     =  []
intersperse s [x]    =  [x]
intersperse s (x:xs) =  x:s: intersperse s xs

intersperse' s []       = []
intersperse' s (xs:xss) = xs ++ concatMap (s:) xss
  1. depth (Node _ l r) = 1 + max (depth l) (depth r) depth _ = 0

  2. data Direction = CCW | CW | OnLine

  3. data Vec2D = C Double Double type Point = Vec2D

    sub :: Vec2D -> Vec2D -> Vec2D sub (C x y) (C x’ y’) = C (x-x’) (y-y’)

    prd :: Vec2D -> Vec2D -> Double prd (C x y) (C x’ y’) = xy’ - x’y

    direction :: Point -> Point -> Point -> Direction direction x y z = case sign (prd (sub y x) (sub z y)) of 1 -> CCW 0 -> OnLine _ -> CW

原書p.63 練習問題

  1. toList :: List a -> [a] toList (Cons x xs) = (:) x (toList xs)

  2. data Tree a = Node (Maybe (Tree a)) (Maybe (Tree a))

第1回

2009-04-18


Last modified : 2011/01/23 23:38:28 JST