zipWith
/mrsekut-book-4774183903/217
code:hs
zipWith :: (a -> b -> c) ->
a
->
b
->
c
zipWith _ [] _ = []
ziipWith _ _ [] = []
zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys
使用例
code:hs
zipWith (+)
1,2
1,2,3
2,4
zipWith (*)
1,2,3
4,5
4,10
フィボナッチ数列
を返す関数
code:ghci(hs)
f = fix $ \fibs -> 1 : 1 : zipWith (+) fibs (tail fibs)
take 10 f --
1,1,2,3,5,8,13,21,34,55